Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# wpf中的mvvm-操作由哪个控件触发_C#_Wpf_Mvvm - Fatal编程技术网

C# wpf中的mvvm-操作由哪个控件触发

C# wpf中的mvvm-操作由哪个控件触发,c#,wpf,mvvm,C#,Wpf,Mvvm,两个按钮(buttonA和buttonB)与单个Icommand(StartPuzzleCommand)绑定 现在的问题是,我如何获得单击时调用代表的按钮。。 这是我学习mvvm的第二天,请提供一些帮助; 我正在使用CommandReference.cs和DelegateCommand.cs预定义类……为什么要用相同的命令绑定按钮?唯一的解决方案是使用不同的命令绑定每个按钮单击事件。如何: startPuzzleCommand = new DelegateCommand<string>

两个按钮(buttonA和buttonB)与单个Icommand(StartPuzzleCommand)绑定

现在的问题是,我如何获得单击时调用代表的按钮。。 这是我学习mvvm的第二天,请提供一些帮助;
我正在使用CommandReference.cs和DelegateCommand.cs预定义类……

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

如何:

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

    });
startPuzzleCommand=newdelegateCommand(
委托(字符串which)
{
});
在您的XAML中:

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

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


我有11个按钮,它们几乎都是基于按钮名称实现的……嗯,那么我猜sixlettervariables的答案在你的情况下会起作用。Thanx很多朋友,我到现在为止还没有测试过,但我知道它会起作用,thankx buddyone我可以在命令参数下传递按钮的完整对象吗like@slash:你可以传递任何你想要的字符串:)好的,有没有一种方法可以让我得到button的完整对象,,,就像button\u click事件中的发送者一样
<Button x:Name="buttonA"
        Command="{Binding StartPuzzleCommand}"
        CommandParameter="A" />

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