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 }
标签:DelegateCommand,AddCommand,Add,调用,new,方法,public,合令 From: https://www.cnblogs.com/CDRPS/p/17263421.html