2

我对 WPF MVVM 模式非常陌生,尤其是commands

ViewModel包含命令

public ICommand MyButtonClickCommand
{
    get { return new RelayCommand(FuncToCall); }
}

private object FuncToCall(object context)
{
    MessageBox.Show("The button was Clicked", "");
    return null;
}

RelayCommandClass.cs

private Action<object> _action;

public RelayCommand(Action<object> action)
{
    _action = action;
}

在编译时我得到FuncToCall(object)' has the wrong return type

谢谢你们

4

4 回答 4

2

当您编写方法名称并单击其建议为您创建方法时,Visual Studio 添加了错误的方法签名。将签名更改为此,一切都会好起来的:

private void FuncToCall(object context)
{
    MessageBox.Show("The button was Clicked", "");
}
于 2013-10-08T12:02:13.730 回答
1

使 FuncToCall() 返回类型Void和删除return语句。

private void FuncToCall(object context)
{
    MessageBox.Show("The button was Clicked", "");
}
于 2013-10-08T12:03:09.590 回答
1

FuncToCall 方法不应返回任何内容。

于 2013-10-08T12:04:01.363 回答
1

FuncToCall() 方法不应有任何返回类型并删除返回语句。

于 2013-10-08T12:16:23.950 回答