winform中devexpress bindcommand无效的解决方法

正常绑定,编译运行无报错,但无法执行command

fluentAPI.BindCommand(commandButton, (x, p) => x.DoSomething(p), x => parameter);

解决方法:
检查command访问权限,在devexpress规范中,command必须为 public void
提示信息:All public void methods with zero or one parameter, declared in POCO ViewModels, are treated as commands.
在view层写绑定的时候,通过alt+enter自动生成的command是Internal修饰的(程序集访问权限),无法访问。

    internal  void DoSomething(int p) {//将  internal改为public
        XtraMessageBox.Show(string.Format(
            "Hello! The parameter passed to command is {0}." + Environment.NewLine +
            "And I'm running, because the `canExecute` condition is `True` for this parameter." + Environment.NewLine +
            "Try to change this parameter!", p));
    }


原文:https://blog.csdn.net/weixin_43862847/article/details/86766417

猜你喜欢

转载自www.cnblogs.com/mq0036/p/10573524.html