Control is not updated after changing CanExecute-Result

in my window I have buttons for loading and saving methods. I use CommandBinding, and the save button has the CanExecute property so that the user does not save the data until they are loaded.

CanExecute-Methode connects to a simple bool value called "canSaveXML"

private void Save_CanExecute(object sender, CanExecuteRoutedEventArgs e) { if (canSaveXML == false) { e.CanExecute = false; } else { e.CanExecute = true; } e.Handled = true; } 

I intend to set canSaveXML = true after loading the data, but the control does not update after changing the value. I read and found out that I need to call CommandManager.InvalidateRequerySposed. I am doing this now and my code looks like this.

 canSaveXML = true; CommandManager.InvalidateRequerySuggested(); 

But the control (button) is still not updated. I'm still disabled until I activate anything in the user interface or minimize / maximize the window. After that, the button is turned on.

What is wrong here?

In the MSDN example, CommandManager.InvalidateRequerySposed is called with the dispatch timer again and again, but I refuse to believe that this will be the only solution.

+4
source share
1 answer

Ok, I found out myself.

 canSaveXML = true; CommandManager.InvalidateRequerySuggested(); 

was the code inside the working background. Not good. You must tell the window manager to call CommandManager.InvalidateRequerySposed ();

+8
source

All Articles