RelayCommand
Mvvm最大的特点就是分离了View和ViewModel,将数据的显示和业务逻辑分开。使用WPF的Binding,我们不仅能够
将数据从ViewModel绑定到View,同时也可以将行为绑定到View。例如,在主界面上点击一个按钮,这个按钮实际完成
的操作是ViewModel中对应的方法。这里我们用到Mvvm框架中的RelayCommand。下面是几种常用的情况
不带参数的RelayCommand
点击按钮,弹出消息框
AppView.xaml
<Grid>
<Button Width="100" Height="30" Command="{Binding ShowMsgCommand}"></Button> </Grid>
AppViewModel.cs
/// <summary>
/// 显示消息命令 /// </summary> public RelayCommand ShowMsgCommand { get; set; } public AppViewModel() { //初始化命令 ShowMsgCommand= new RelayCommand(ShowMsg); } /// <summary> /// 命令具体实现 /// </summ