DelegateCommand-最简单的合令调用。
View代码
<StackPanel>
<Button Content="方法一" Command="{Binding AddCommand}"></Button>
</StackPanel>
ViewModel代码
1 public DelegateCommand? AddCommand 2 { 3 set; get; 4 } 5 public MainWindowViewModel() 6 { 7 //方法一 8 //AddCommand = new DelegateCommand(Add); 9 //方法二 10 //AddCommand = new DelegateCommand(new Action(Add)); 11 //方法三 12 //Lamda表达式代替方法 13 //AddCommand = new DelegateCommand(new Action(() => { Add(); })); 14 15 16 } 17 18 private void Add() 19 { 20 //写入需要执行的代码; 21 MessageBox.Show("方法一"); 22 }
浙公网安备 33010602011771号