How to send parameter to ICommand 's Execute m

2019-09-11 07:50发布

I have gone through few MVVM examples in SL/WPF and the very basic thing here is to implement ICommand interface. I have understood how MVVM works. However, I have a doubt regarding Execute method of ICommand interface.

The class which implements ICommand has Execute method as shown below.

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

In every example, I see that parameter in above method is NULL. Why? Can someone post a simple example of MVVM where this object parameter is put to use and not null ?

1条回答
走好不送
2楼-- · 2019-09-11 08:05

In the XAML you can set a CommandParameter

<Button Command="{Binding MyCommand}" CommandParameter="SomeData" />
查看更多
登录 后发表回答