简体   繁体   English

为什么命令不起作用并且没有向 TextBlock 添加任何值?

[英]Why does the command not work and no values are added to the TextBlock?

I'm currently trying to figure out the MVVM pattern in wpf, and I'm writing a test application, but I ran into a problem.我目前正在尝试找出 wpf 中的 MVVM 模式,并且正在编写一个测试应用程序,但遇到了问题。 The CountCommand does not work. CountCommand 不起作用。 Initially, the command was synchronous and also did not work.最初,该命令是同步的,也不起作用。 And if you enter "Application.Current.Shutdown();"如果您输入“Application.Current.Shutdown();” then it will close the application by clicking on the TextBlock.然后它将通过单击 TextBlock 关闭应用程序。 This means that the team itself is working and something is wrong in its body.这意味着团队本身正在工作,但它的身体出现了问题。

 internal class MainWindowViewModel
{
    public int i { get; set; }
    public ICommand CountCommand{ get; set; }
    private async void Execute(object p) => await Task.Run(() => i++);
    private bool CanExecute(object p) => true;


    public MainWindowViewModel()
    {
        CountCommand = new CommendBase(Execute, CanExecute);
    }
    
}

The command itself should add 1 when clicking on the Textblock单击文本块时,命令本身应加 1

enter image description here在此处输入图像描述

i think it might have something to do with this: How to capture a variable in C#我认为这可能与此有关: How to capture a variable in C#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM