I am using MVVM-Light RelayCommand
private ICommand myRevertCmd;
public ICommand Revert
{
get
{
if (myRevertCmd == null)
{
myRevertCmd = new RelayCommand(RevertExecute, CanRevertExecute);
}
return myRevertCmd;
}
}
private void RevertExecute()
{
searchType = SearchType.Revert;
SearchStart();
}
private bool CanRevertExecute()
{
return isRevertEnabled;
}
I have some code that changes the value of isRevertEnabled but the linked button does not change. After some searching I found that you can use to force the re-evaluation of the button states
// force the GUI to re-evaluate the state of the buttons
CommandManager.InvalidateRequerySuggested();
But this doesn’t work. Does any one have any suggestions?
I would turn the isRevertEnabled flag into a property and call the OnPropertyChanged method from there (you need to implement the INotifyPropertyChanged interface). At the point where you change the flag, you need to use the property, e.g. IsRevertEnabled = true.