How to Notify Command to evaluate in mvvmlight

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();

        }
    }
posted @ 2016-05-29 14:44  kongshu  阅读(110)  评论(0编辑  收藏  举报