首页 > 其他分享 >DelegateCommand-最简单的合令调用。

DelegateCommand-最简单的合令调用。

时间:2023-03-27 23:24:48浏览次数:25  
标签:DelegateCommand AddCommand Add 调用 new 方法 public 合令

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

相关文章