wpf中的mvvm - Action由哪个控件触发

时间:2011-06-21 17:26:43

标签: c# wpf mvvm

两个按钮(buttonA和buttonB)与单个Icommand(StartPuzzleCommand)捆绑在一起。

  startPuzzleCommand = new DelegateCommand(delegate()
                {
                   // which control fire this action

                }); 

现在的问题是如何在点击时获得哪个按钮调用代理... 那么这是我学习mvvm的第二天,请提出一些帮助; 我正在使用CommandReference.cs和DelegateCommand.cs预定义类......

2 个答案:

答案 0 :(得分:4)

怎么样:

startPuzzleCommand = new DelegateCommand<string>(
    delegate(string which)
    {

    });

在你的XAML中:

<Button x:Name="buttonA"
        Command="{Binding StartPuzzleCommand}"
        CommandParameter="A" />

<Button x:Name="buttonB"
        Command="{Binding StartPuzzleCommand}"
        CommandParameter="B" />

答案 1 :(得分:0)

为什么用相同的命令绑定按钮?唯一的解决方案是使用不同的命令绑定每个按钮单击事件。

相关问题