我在 SL/WPF 中浏览了一些 MVVM 示例,这里最基本的事情是实现 ICommand
界面。我已经了解了 MVVM 的工作原理。但是,我对 Execute
有疑问。 ICommand
的方法界面。
实现 ICommand
的类有 Execute
方法如下图。
public void Execute(object parameter) //Method to call when the command is invoked
{
// pointer to a method to be executed
}
在每个示例中,我看到上述方法中的参数是
NULL
.为什么?有人可以发布一个简单的 MVVM 示例,其中使用此对象参数而不是 null 吗?
最佳答案
在 XAML 中,您可以设置 CommandParameter
<Button Command="{Binding MyCommand}" CommandParameter="SomeData" />
关于c# - 如何将参数发送到 ICommand 的 Execute 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16279255/