相关疑难解决方法(0)

如何将变量作为CommandParameter传递

我正在尝试将ViewModel中的变量作为参数发送到命令.该命令如下所示:

public class EditPersonCommand : ICommand
{
  private bool _CanExecute = false;

  public bool CanExecute(object parameter)
  {
     PersonModel p = parameter as PersonModel;
     CanExecuteProperty = (p != null) && (p.Age > 0);
     return CanExecuteProperty;
  }

  public event EventHandler CanExecuteChanged;

  public void Execute(object parameter) { }

  private bool CanExecuteProperty
  {
     get { return _CanExecute; }
     set
     {
        if (_CanExecute != value)
        {
           _CanExecute = value;
           EventHandler can_execute = CanExecuteChanged;
           if (can_execute != null)
           {
              can_execute.Invoke(this, EventArgs.Empty);
           }
        }
     }
  }
} …
Run Code Online (Sandbox Code Playgroud)

c# wpf command mvvm commandparameter

8
推荐指数
2
解决办法
3万
查看次数

标签 统计

c# ×1

command ×1

commandparameter ×1

mvvm ×1

wpf ×1