How to Notify Command to evaluate in mvvmlight

时间:2022-05-26 19:29:43

How to Raize Command to evalituate in mvvm

  1. In mvvmlight, we bind our control to the relaycommand object. But, the commmand only execute the CanExecute() onetime, if some specifies changed, how could we notify the control to re-evaluate.

    Im mvvm light, we can find, two elements in RelayCommand: event CanExecuteChanged, RaiseCanExecuteChagned(), so we can add our customized event handles to the event, and we can call the RaiseCanExecuteChanged() function to raise the event,

Sample code:

 public int Index
{
get
{
return _index;
}
set
{
_index = value;
RaisePropertyChanged("");
((RelayCommand<string>)BackCommand).RaiseCanExecuteChanged();
((RelayCommand<string>)NextCommand).RaiseCanExecuteChanged(); }
}