gpt4 book ai didi

c# - MVVM命令错误

转载 作者:行者123 更新时间:2023-12-03 10:13:32 27 4
gpt4 key购买 nike

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

ViewModel 包含 Command

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)'有错误的返回类型

谢谢大家

最佳答案

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

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

关于c# - MVVM命令错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19247122/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com