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         }
复制代码

 

posted @   Windows窗  阅读(179)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示