【问题标题】:WPF command binding: CanExecute parameterWPF 命令绑定:CanExecute 参数
【发布时间】:2013-10-08 16:36:42
【问题描述】:

传递给绑定命令的CanExecute方法的参数是绑定控件中指定的CommandParameter吗?如果不是,它来自哪里?

【问题讨论】:

  • 没错,就是CommandParameter

标签: wpf binding


【解决方案1】:

CommandParameter 被发送到CanExecuteExecute(d) 事件。

【讨论】:

    【解决方案2】:

    亚历克斯·柯蒂斯是对的:

    public bool CanExecute(object parameter)
    public void Execute(object parameter)
    

    将设置为CommandParameter 的对象用于命令。

    在调用ICommand 的OnCanExecuteChanged(EventArgs e) 时知道这一点也很好,因为此方法不会让您传递任何参数。所以 CanExecute 必须使用之前设置的 CommandParameter。

    【讨论】:

      猜你喜欢
      • 2010-12-17
      • 1970-01-01
      • 2011-01-10
      • 2016-05-07
      • 2016-08-21
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多