WPF MVVM入门系列教程(六、ViewModel案例演示)

  🧭 WPF MVVM入门系列教程

  • 一、MVVM模式介绍
  • 二、依赖属性
  • 三、数据绑定
  • 四、ViewModel
  • 五、命令和用户输入
  • 六、ViewModel案例演示

在前面的文章中,介绍了ViewModel的基础概念

本文会使用一些实例来进行ViewModel的演示

一个基础的数据展示示例

假设我们要在界面上对一本书籍的详细信息进行展示。

首先我们定义一下View

MainWindow.xaml

界面上我们定义了两列,左边一列用于展示书籍封面,右边一列用于展示详细信息

 1 <Window x:Class="_1_ViewModelStartup.MainWindow"2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"6         xmlns:local="clr-namespace:_1_ViewModelStartup"7         mc:Ignorable="d"8         Title="MainWindow" Height="500" Width="900" WindowStartupLocation="CenterScreen">9     <Grid>
10         <Grid.ColumnDefinitions>
11             <ColumnDefinition/>
12             <ColumnDefinition/>
13         </Grid.ColumnDefinitions>
14 
15         <Image Source="{Binding Book.CoverImageUrl}" Stretch="Uniform" Margin="20"></Image>
16 
17         <StackPanel Grid.Column="1">
18             <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Book.Title}" FontSize="25" FontWeight="Bold" Margin="10"></TextBlock>
19             <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Book.Descrption}" FontSize="20" Foreground="Silver" Margin="10"></TextBlock>
20             <Separator Height="1" Foreground="Silver" Margin="10"></Separator>
21             <StackPanel Orientation="Horizontal" Margin="10">
22                 <Label Content="作者:"></Label>
23                 <Label Content="{Binding Book.Author}" Foreground="Silver"  ></Label>
24             </StackPanel>
25             <StackPanel Orientation="Horizontal" Margin="10">
26                 <Label Content="出版社:"></Label>
27                 <Label Content="{Binding Book.Publish}" Foreground="Silver"  ></Label>
28             </StackPanel>
29             <StackPanel Orientation="Horizontal" Margin="10">
30                 <Label Content="价格 ¥: " Foreground="Red" FontWeight="Bold"></Label>
31                 <Label Content="{Binding Book.Price}" Foreground="Silver"  ></Label>
32             </StackPanel>
33             <StackPanel Orientation="Horizontal" Margin="10">
34                 <Label Content="出版日期:"></Label>
35                 <Label Content="{Binding Book.Date}" Foreground="Silver"  ></Label>
36             </StackPanel>
37         </StackPanel>
38     </Grid>
39 
40 </Window>

然后我们定义一下Model

Book.cs

 1 public class Book : INotifyPropertyChanged2 {3     private string title;4 5     public string Title6     {7         get => title;8         set9         {
10             title = value;
11             RaiseChanged();
12         }
13     }
14 
15     private string author;
16     public string Author
17     {
18         get => author;
19         set
20         {
21             author = value;
22             RaiseChanged();
23         }
24     }
25 
26     private string publish;
27 
28     public string Publish
29     {
30         get => publish;
31         set
32         {
33             publish = value;
34             RaiseChanged();
35         }
36     }
37 
38     private string price;
39 
40     public string Price
41     {
42         get => price;
43         set
44         {
45             price = value;
46             RaiseChanged();
47         }
48     }
49 
50     private string date;
51     public string Date
52     {
53         get => date;
54         set
55         {
56             date = value;
57             RaiseChanged();
58         }
59     }
60 
61     private string description;
62 
63     public string Descrption
64     {
65         get => description;
66         set
67         {
68             description = value;
69             RaiseChanged();
70         }
71     }
72 
73 
74     private string coverImageUrl;
75 
76     public string CoverImageUrl
77     {
78         get => coverImageUrl;
79         set
80         {
81             coverImageUrl = value;
82             RaiseChanged();
83         }
84     }
85 
86 
87     public event PropertyChangedEventHandler PropertyChanged;
88 
89 
90     public void RaiseChanged([CallerMemberName] string memberName = "")
91     {
92         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName));
93     }
94 }

定义ViewModel

MainWindowViewModel.cs

ViewModel里,定义一个Book对象,并进行数据初始化。

View上的元素分别绑定到了该对象的各个属性。

 1   public class MainWindowViewModel : INotifyPropertyChanged2   {3       private Book book;4 5       public Book Book 6       {7           get => book;8           set9           {
10               book = value;
11               PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Book"));
12           }
13       }
14 
15       public MainWindowViewModel()
16       {
17           LoadBook();
18       }
19 
20       public event PropertyChangedEventHandler PropertyChanged;
21 
22       private void LoadBook()
23       {
24           Book = new Book();
25           Book.CoverImageUrl = "http://img3m1.ddimg.cn/16/5/29681701-1_w_1709623057.jpg";
26           Book.Title = "小学生C++创意编程(视频教学版)";
27           Book.Descrption = "本书让入门C++变得轻松易懂,逐步入学。学习一步一个台阶,让孩子不会被其中的难度而吓退。";
28           Book.Author = "刘凤飞";
29           Book.Publish = "清华大学出版社";
30           Book.Date = "2024年01月 ";
31           Book.Price = "74.00";
32       }
33   }

设置DataContext

1     public partial class MainWindow : TianXiaTech.BlurWindow
2     {
3         public MainWindow()
4         {
5             InitializeComponent();
6 
7             this.DataContext = new MainWindowViewModel();
8         }
9     }

运行效果如下:

带列表功能的示例

接下来我们将上面的示例进行升级,增加列表功能,并支持列表排序

首先我们升级一下界面,将书籍封面,移动到右上角,左侧增加一个ListBox。

其中ListBox使用数据模板定义了数据呈现方式。

 1 <Window x:Class="_2_ShowBookList.MainWindow"2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"6         xmlns:local="clr-namespace:_2_ShowBookList"7         mc:Ignorable="d"8         Title="MainWindow" Height="450" Width="800">9     <Grid>
10         <Grid.ColumnDefinitions>
11             <ColumnDefinition Width="300"/>
12             <ColumnDefinition/>
13         </Grid.ColumnDefinitions>
14 
15         <Grid>
16             <Grid.RowDefinitions>
17                 <RowDefinition/>
18                 <RowDefinition Height="45"/>
19             </Grid.RowDefinitions>
20 
21             <ListBox ItemsSource="{Binding BookList}" SelectedItem="{Binding Book}" Margin="5">
22                 <ListBox.ItemTemplate>
23                     <DataTemplate>
24                         <Grid>
25                             <Grid.RowDefinitions>
26                                 <RowDefinition/>
27                                 <RowDefinition/>
28                             </Grid.RowDefinitions>
29 
30                             <!--使用数据模板,让书名支持换行-->
31                             <TextBlock Text="{Binding Title}" FontWeight="Bold" TextWrapping="WrapWithOverflow" Width="260"></TextBlock>
32                             <Grid Grid.Row="1" Margin="0,5,0,0">
33                                 <Grid.ColumnDefinitions>
34                                     <ColumnDefinition/>
35                                     <ColumnDefinition/>
36                                 </Grid.ColumnDefinitions>
37 
38                                 <Label Content="{Binding Author}"></Label>
39                                 <TextBlock Text="{Binding Price,StringFormat={}{0}元}" HorizontalAlignment="Left"  Grid.Column="1"></TextBlock>
40                             </Grid>
41                         </Grid>
42                     </DataTemplate>
43                 </ListBox.ItemTemplate>
44             </ListBox>
45 
46             <DockPanel LastChildFill="False" Grid.Row="1">
47                 <Button Content="价格升序" VerticalAlignment="Center" Margin="5,0,0,0" Command="{Binding OrderByPriceAscCommand}"></Button>
48                 <Button Content="价格降序" VerticalAlignment="Center" Margin="5,0,0,0" Command="{Binding OrderByPriceDescCommand}"></Button>
49             </DockPanel>
50         </Grid>
51 
52         <StackPanel Grid.Column="1">
53             <Image Source="{Binding Book.CoverImageUrl}" Stretch="Uniform" Margin="20" Height="150"></Image>
54 
55             <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Book.Title}" FontWeight="Bold" Margin="5"></TextBlock>
56             <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Book.Descrption}" Foreground="Silver" Margin="5"></TextBlock>
57             <Separator Height="1" Foreground="Silver" Margin="2"></Separator>
58             <StackPanel Orientation="Horizontal" Margin="5">
59                 <Label Content="作者:"></Label>
60                 <Label Content="{Binding Book.Author}" Foreground="Silver"  ></Label>
61             </StackPanel>
62             <StackPanel Orientation="Horizontal" Margin="5">
63                 <Label Content="出版社:"></Label>
64                 <Label Content="{Binding Book.Publish}" Foreground="Silver"  ></Label>
65             </StackPanel>
66             <StackPanel Orientation="Horizontal" Margin="5">
67                 <Label Content="价格 ¥: " Foreground="Red" FontWeight="Bold"></Label>
68                 <Label Content="{Binding Book.Price}" Foreground="Silver"  ></Label>
69             </StackPanel>
70             <StackPanel Orientation="Horizontal" Margin="5">
71                 <Label Content="出版日期:"></Label>
72                 <Label Content="{Binding Book.Date}" Foreground="Silver"  ></Label>
73             </StackPanel>
74         </StackPanel>
75     </Grid>
76 
77 </Window>

此外,我们还要注意一下界面绑定:

ListBox的数据源绑定到BookList集合,SelectedItem绑定到Book对象

1 ListBox ItemsSource="{Binding BookList}" SelectedItem="{Binding Book}"

另外还增加了排序按钮,分别绑定到两个不同的Command

1 <Button Content="价格升序" VerticalAlignment="Center" Margin="5,0,0,0" Command="{Binding OrderByPriceAscCommand}"></Button>
2 <Button Content="价格降序" VerticalAlignment="Center" Margin="5,0,0,0" Command="{Binding OrderByPriceDescCommand}"></Button>

然后我们在前面的基础上升级一下ViewModel

 1  public class MainWindowViewModel : INotifyPropertyChanged2  {3      private Book book;4 5      public Book Book6      {7          get => book;8          set9          {
10              book = value;
11              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Book"));
12          }
13      }
14 
15      private ObservableCollection<Book> bookList = new ObservableCollection<Book>();
16 
17      public ObservableCollection<Book> BookList
18      {
19          get => bookList;
20          set
21          {
22              bookList = value;
23              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("BookList"));
24          }
25      }
26 
27      public ICommand OrderByPriceAscCommand { get; private set; }
28 
29      public ICommand OrderByPriceDescCommand { get; private set; }
30 
31 
32      public MainWindowViewModel()
33      {
34          OrderByPriceAscCommand = new RelayCommand(OrderByPriceAsc);
35          OrderByPriceDescCommand = new RelayCommand(OrderByPriceDesc);
36 
37          LoadBook();
38      }
39 
40      private void OrderByPriceDesc()
41      {
42          BookList = new ObservableCollection<Book>(BookList.OrderByDescending(x => x.Price));
43      }
44 
45      private void OrderByPriceAsc()
46      {
47          BookList = new ObservableCollection<Book>(BookList.OrderBy(x => x.Price));
48      }
49 
50      public event PropertyChangedEventHandler PropertyChanged;
51 
52      private void LoadBook()
53      {
54          Book book = new Book();
55          book.CoverImageUrl = "http://img3m1.ddimg.cn/16/5/29681701-1_w_1709623057.jpg";
56          book.Title = "小学生C++创意编程(视频教学版)";
57          book.Descrption = "本书让入门C++变得轻松易懂,逐步入学。学习一步一个台阶,让孩子不会被其中的难度而吓退。";
58          book.Author = "刘凤飞";
59          book.Publish = "清华大学出版社";
60          book.Date = "2024年01月 ";
61          book.Price = 74.00f;
62 
63          Book book2 = new Book();
64          book2.CoverImageUrl = "http://img3m4.ddimg.cn/64/13/29798074-1_u_1731275892.jpg";
65          book2.Title = "漫画趣读西游记(7-14岁)和大人一起读四大名著儿童文学,十万个为什么中小学课外阅读快乐读书吧";
66          book2.Descrption = "拼音标注、无障阅读、名著导读、有声伴读、Q版漫画、全彩印刷,鲜活的人物形象,激发兴趣,提升孩子的学习力!";
67          book2.Author = "陈春燕";
68          book2.Publish = "四川美术出版社";
69          book2.Date = "2024年09月";
70          book2.Price = 4.89f;
71 
72          BookList.Add(book);
73          BookList.Add(book2);
74      }
75  }

运行效果如下:

带新增功能的示例

我们在前面列表的基础上,再进行升级,支持从界面新增书籍。

 1   <Grid>2       <Grid.RowDefinitions>3           <RowDefinition/>4           <RowDefinition Height="35"/>5       </Grid.RowDefinitions>6 7       <Grid>8           <Grid.ColumnDefinitions>9               <ColumnDefinition/>
10               <ColumnDefinition/>
11           </Grid.ColumnDefinitions>
12 
13           <Image Stretch="Uniform" Margin="0,0,0,30" Source="{Binding NewBook.CoverImageUrl}"></Image>
14           <Button Content="浏览封面" HorizontalAlignment="Center" VerticalAlignment="Bottom" Command="{Binding BrowseCoverCommand}"></Button>
15 
16           <StackPanel Grid.Column="1">
17               <StackPanel Orientation="Horizontal" Margin="10">
18                   <Label Content="书名:"></Label>
19                   <TextBox Text="{Binding NewBook.Title}" Foreground="Silver" Width="200" ></TextBox>
20               </StackPanel>
21               <StackPanel Orientation="Horizontal" Margin="10">
22                   <Label Content="描述:"></Label>
23                   <TextBox Text="{Binding NewBook.Descrption}" Foreground="Silver" Width="200" ></TextBox>
24               </StackPanel>
25               <StackPanel Orientation="Horizontal" Margin="10">
26                   <Label Content="作者:"></Label>
27                   <TextBox Text="{Binding NewBook.Author}" Foreground="Silver" Width="200" ></TextBox>
28               </StackPanel>
29               <StackPanel Orientation="Horizontal" Margin="10">
30                   <Label Content="出版社:"></Label>
31                   <TextBox Text="{Binding NewBook.Publish}" Foreground="Silver"  Width="200"></TextBox>
32               </StackPanel>
33               <StackPanel Orientation="Horizontal" Margin="10">
34                   <Label Content="价格 ¥: " Foreground="Red" FontWeight="Bold"></Label>
35                   <TextBox Text="{Binding NewBook.Price}" Foreground="Silver"  Width="200"></TextBox>
36               </StackPanel>
37               <StackPanel Orientation="Horizontal" Margin="10">
38                   <Label Content="出版日期:"></Label>
39                   <TextBox Text="{Binding NewBook.Date}" Foreground="Silver" Width="200"></TextBox>
40               </StackPanel>
41           </StackPanel>
42       </Grid>
43 
44       <Button Content="新增" Width="88" Height="28" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Command="{Binding AddBookCommand}"/>
45   </Grid>

需要注意的是,这里我们将增加书籍的信息绑定到了一个NewBook对象。

此外,我们还定义了BrowseCoverCommand和AddBookCommand,分别用于浏览书籍封面和新增加书籍

然后我们更新ViewModel

这里为了防止混淆,将前面示例部分的代码移除了,完整的代码可以参考文末的示例代码

 1 public class MainWindowViewModel2 {3     ... 4 5     private Book newBook = new Book();6 7     public Book NewBook8     {9         get => newBook;
10         set
11         {
12             newBook = value;
13             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("NewBook"));
14         }
15     }
16 
17     public ICommand BrowseCoverCommand { get; private set; }
18 
19     public ICommand AddBookCommand { get; private set; }
20 
21 
22     public event PropertyChangedEventHandler? PropertyChanged;
23 
24     public MainWindowViewModel()
25     {
26         BrowseCoverCommand = new RelayCommand(BrowseCover);
27         AddBookCommand = new RelayCommand(AddBook);
28      
29         LoadDemoData();   
30     }
31 
32     private void LoadDemoData()
33     {
34         Book book = new Book();
35         book.CoverImageUrl = "http://img3m1.ddimg.cn/16/5/29681701-1_w_1709623057.jpg";
36         book.Title = "小学生C++创意编程(视频教学版)";
37         book.Descrption = "本书让入门C++变得轻松易懂,逐步入学。学习一步一个台阶,让孩子不会被其中的难度而吓退。";
38         book.Author = "刘凤飞";
39         book.Publish = "清华大学出版社";
40         book.Date = "2024年01月 ";
41         book.Price = "74.00";
42 
43         Book book2 = new Book();
44         book2.CoverImageUrl = "http://img3m4.ddimg.cn/64/13/29798074-1_u_1731275892.jpg";
45         book2.Title = "漫画趣读西游记(7-14岁)和大人一起读四大名著儿童文学,十万个为什么中小学课外阅读快乐读书吧";
46         book2.Descrption = "拼音标注、无障阅读、名著导读、有声伴读、Q版漫画、全彩印刷,鲜活的人物形象,激发兴趣,提升孩子的学习力!";
47         book2.Author = "陈春燕";
48         book2.Publish = "四川美术出版社";
49         book2.Date = "2024年09月";
50         book2.Price = "4.89";
51 
52         BookList.Add(book);
53         BookList.Add(book2);
54     }
55 
56     private void AddBook()
57     {
58         var tempBook = new Book();
59         tempBook.Title = NewBook.Title;
60         tempBook.Descrption = NewBook.Descrption;
61         tempBook.Author = NewBook.Author;
62         tempBook.Publish = NewBook.Publish;
63         tempBook.Price = NewBook.Price;
64         tempBook.Date = NewBook.Date;
65         tempBook.CoverImageUrl = NewBook.CoverImageUrl;
66 
67         //将NewBook添加到列表中
68         BookList.Add(tempBook);
69 
70         //重置NewBook
71         NewBook.Title = "";
72         NewBook.Descrption = "";
73         NewBook.Author = "";
74         NewBook.Publish = "";
75         NewBook.Price = "";
76         NewBook.Date = "";
77         NewBook.CoverImageUrl = null;
78     }
79 
80     private void BrowseCover()
81     {
82         Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
83         openFileDialog.Filter = "图片文件|*.jpg;*.bmp;*.png";
84 
85         if (openFileDialog.ShowDialog() == true)
86         {
87             NewBook.CoverImageUrl = openFileDialog.FileName;
88         }
89     }
90     
91     ...
92 }

运行效果如下:

示例代码

https://github.com/zhaotianff/WPF-MVVM-Beginner/tree/main/6_ViewModelDemo

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/80092.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第2章 算法分析基础

2-1 算法的时间复杂度分析 2.1.1 输入规模与基本语句 输入规模&#xff1a;算法处理数据的规模&#xff0c;通常用 n 表示。 基本语句&#xff1a;执行次数与输入规模直接相关的关键操作。 例2.1 顺序查找 int SeqSearch(int A[], int n, int k) { for (int i 0; i < n…

QT高级(1)QTableView自定义委托集合,一个类实现若干委托

自定义委托集合 1同系列文章2 功能3 源码 1同系列文章 QT中级&#xff08;1&#xff09;QTableView自定义委托&#xff08;一&#xff09;实现QSpinBox、QDoubleSpinBox委托 QT中级&#xff08;2&#xff09;QTableView自定义委托&#xff08;二&#xff09;实现QProgressBar委…

webrtc 视频直播

webrtc 是一种开源的音视频通信技术&#xff0c;可以不借助中间媒介建立浏览器点对点&#xff08;peer-to-peer&#xff09;连接&#xff0c;实现音视频以及其他数据的传输。webrtc具有平台兼容性&#xff0c;低延迟与高实时的优点。今天主要记录一下webrtc的使用记录&#xff…

游戏引擎学习第261天:切换到静态帧数组

game_debug.cpp: 将ProfileGraph的尺寸初始化为相对较大的值 今天的讨论主要围绕性能分析器&#xff08;Profiler&#xff09;以及如何改进它的可用性展开。当前性能分析器已经能够正常工作&#xff0c;但我们希望通过一些改进&#xff0c;使其更易于使用&#xff0c;特别是在…

three.js设置物体轮廓发光和物体发光

设置物体轮廓发光 <script setup> import * as THREE from three; import { OrbitControls } from three/addons/controls/OrbitControls.js; // 导入后期合成 import { EffectComposer } from three/examples/jsm/postprocessing/EffectComposer.js; import { RenderPas…

homebrew安装配置Python(MAC版)

Mac系统自带python路径为: /System/Library/Frameworks/Python.framework/Versionbrew 安装 Python3 在终端输入以下命令&#xff1a; brew search python3 # 查看支持安装的版本 brew install python3就可以轻松easy安装python了&#xff0c;安装完成后提示 查看 pyth…

如何建设网站?网站建设简单步骤有哪些?

新手如何开展网站建设&#xff1f;网站建设包括哪些步骤&#xff1f; 在开展网站建设之前先清楚了解网站建设的流程和步骤&#xff1a;注册域名、租用虚拟主机/服务器、建站工具的选取、网站建设流程详细流程共计7步&#xff0c;分别是注册域名、域名实名制、服务器或虚拟主机、…

当K8S容器没有bash时高阶排查手段

遇到容器没有bash甚至没有sh的情况&#xff0c;就像被困在没有门窗的房间。但真正的K8S运维高手&#xff0c;即使面对这种情况也能游刃有余。 一、无Shell容器三大特征 极简主义&#xff1a;移除所有非必要组件&#xff08;如/bin/sh&#xff09;安全加固&#xff1a;减少攻击…

Python案例实战《手势识别》

目录 1、效果图2、手势识别关键步骤&#xff08;1&#xff09; 导入必要的库&#xff08;2&#xff09;配置 MediaPipe&#xff08;3&#xff09;启动摄像头&#xff08;4&#xff09;设置手指张开判断的距离阈值&#xff08;5&#xff09;计算手指之间的欧几里得距离&#xff…

5G赋能农业物联网:智能化种植的新纪元

5G赋能农业物联网&#xff1a;智能化种植的新纪元 在农业领域&#xff0c;精准化、智能化已成为现代农业发展的方向。而5G的出现&#xff0c;让农业物联网&#xff08;Agri-IoT&#xff09;突破了传统的瓶颈&#xff0c;真正实现了实时监测、高效数据传输、智能化决策&#xf…

VIVADO IP核整理(二)——FFT

目录 IP 核配置IP 核接口s_axis_config_tdata 配置输入输出端口描述 仿真 参考&#xff1a;FFT IP核 详细介绍 参考&#xff1a;官方文档介绍 IP 核配置 在 IP Catalog 中搜索&#xff1a;Fast Fourier Transform 按照上图所示进行配置&#xff0c;下文对配置内容进行详述。 …

【计算机基础】任意进制转换方法详解

文章目录 一、通用进制转换(整数部分)1. R进制转十进制(整数)2. 十进制转R进制(整数)二、通用进制转换(小数部分)1. 十进制小数转R进制2. R进制小数转十进制三、二进制与十进制互转(整数部分)1. 二进制转十进制(整数)2. 十进制转二进制(整数)四、二进制与十进制互…

鼠标交互初体验:点击屏幕生成彩色气泡(EGE 库基础)

在图形编程领域&#xff0c;实现与用户的交互是让程序变得生动有趣的关键环节。对于初学者来说&#xff0c;使用合适的图形库能大幅降低开发难度&#xff0c;快速实现创意想法。EGE 库作为一款简单易用且功能强大的 C/C 图形库&#xff0c;特别适合新手入门图形交互编程。本文将…

Office 三大组件Excel、Word、Access 里 VBA 区别对比

以下是Excel、Word和Access在VBA中的主要区别对比及详细说明: 核心对象模型 Excel Workbook(工作簿)→ Worksheet(工作表)→ Range(单元格区域) 核心围绕单元格数据处理,如 Cells(1,1).Value = "数据" Word Document(文档)→ Range(文本范围)→ Paragrap…

【上位机——MFC】对象和控件绑定

对象和控件绑定 将控件窗口和类对象绑定具有两大作用 如果和数据类对象绑定&#xff0c;对象和控件可以进行数据交换。 如果和控件类对象绑定&#xff0c;对象就可以代表整个控件。 与数据类型对象绑定的使用 数据类型对象和控件可实现数据交互重写父类成员虚函数DoDataExch…

Excel处理控件Aspose.Cells教程:压缩Excel文件完整指南

Excel 电子表格是管理、分析和可视化数据的有效工具&#xff0c;但随着文件复杂度的增加&#xff0c;它们很快就会变得臃肿。无论是由于数据集庞大、嵌入图片、格式过多还是隐藏工作表&#xff0c;Excel 文件的大小都可能迅速膨胀&#xff0c;导致打开速度变慢、难以通过电子邮…

软考【软考高级QA】

软考高级QA 1.操作系统管理和调度进程时&#xff0c;有哪些状态&#xff1f;&#xff08;5种&#xff09;2.操作系统管理和调度进程时&#xff0c;会进行哪些状态转换&#xff1f; 1.操作系统管理和调度进程时&#xff0c;有哪些状态&#xff1f;&#xff08;5种&#xff09; …

神经网络基础-从零开始搭建一个神经网络

一、什么是神经网络 人工神经网络&#xff08;Articial Neural Network&#xff0c;简写为ANN&#xff09;也称为神经网络&#xff08;NN),是一种模仿生物神经网络和功能的计算模型&#xff0c;人脑可以看做是一个生物神经网络&#xff0c;由众多的神经元连接而成&#xff0c;…

Golang 接口 vs Rust Trait:一场关于抽象的哲学对话

一、引言 在现代编程语言中&#xff0c;接口&#xff08;Interface&#xff09; 和 Trait 是实现多态和抽象行为的关键机制。它们允许我们定义行为契约&#xff0c;让不同的类型共享相同的语义接口&#xff0c;从而提升代码的复用性和扩展性。 Go 和 Rust 分别代表了两种截然…

java实现一个操作日志模块功能,怎么设计

为了设计一个高效、可靠且可扩展的操作日志模块&#xff0c;可以结合 ​AOP&#xff08;面向切面编程&#xff09;​、异步处理​&#xff08;多线程或MQ&#xff09;以及合理的存储策略&#xff0c;具体方案如下&#xff1a; ​1. 技术选型与架构设计​ ​​(1) AOP 实现非侵…