Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CommandManager.InvalidateRequerySuggested does not cause a requery on CanExecute in MVVM-Light

Tags:

wpf

mvvm-light

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?

like image 880
Andrea Avatar asked May 17 '11 09:05

Andrea


1 Answers

Just to add another possible solution, in my case I needed to call CommandManager.InvalidateRequerySuggested on the UI thread using Application.Current.Dispatcher.Invoke.

like image 146
Jens Avatar answered Sep 20 '22 01:09

Jens