WPF ViewModel Commands CanExecute issue

后端 未结 5 758
情书的邮戳
情书的邮戳 2020-12-09 11:38

I\'m having some difficulty with Context Menu commands on my View Model.

I\'m implementing the ICommand interface for each command within the View Model, then creati

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 12:28

    To complete Will's answer, here's a "standard" implementation of the CanExecuteChanged event :

    public event EventHandler CanExecuteChanged
    {
        add { CommandManager.RequerySuggested += value; }
        remove { CommandManager.RequerySuggested -= value; }
    }
    

    (from Josh Smith's RelayCommand class)

    By the way, you should probably consider using RelayCommand or DelegateCommand : you'll quickly get tired of creating new command classes for each and every command of you ViewModels...

提交回复
热议问题