c# - 如何将参数发送到 ICommand 的 Execute 方法

标签 c# wpf silverlight mvvm

我在 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/

相关文章:

ListView 中的 Wpf 组合框绑定(bind)

.net - 除了 "copy and paste inheritence"之外,还有什么方法可以与 Silverlight 应用程序共享 .net 类吗?

c# - 泛型和 Action 委托(delegate)

WPF 508 合规性

WPF:带按钮的动态菜单

visual-studio-2010 - VS2010 : Unable to start debugging Cannot locate Microsoft Internet Explorer

c# - 存储 Windows Phone 的设置

c# - 使 Guid 属性线程安全

c# - C# 中的线程和异步操作

c# - 系统.Net.WebException : The remote server returned an error: (530) Not logged in