我在SL/WPF中浏览了几个MVVM示例,这里最基本的是实现ICommand接口(interface)。我已经了解了MVVM的工作原理。但是,我对Execute接口(interface)的ICommand方法有疑问。

实现ICommand的类具有Execute方法,如下所示。

public void Execute(object parameter) //Method to call when the command is invoked
        {
          // pointer to a method to be executed
        }

在每个示例中,我看到上述方法中的参数是NULL。为什么?有人可以发布一个使用该对象参数而不是null的MVVM的简单示例吗?

最佳答案

在XAML中,您可以设置CommandParameter

<Button Command="{Binding MyCommand}" CommandParameter="SomeData" />

关于c# - 如何将参数发送到ICommand的Execute方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16279255/

10-13 07:06