CommandManager.InvalidateRequerySuggested Method ()

 

Forces the CommandManager to raise the RequerySuggested event.

Namespace:   System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

public static void InvalidateRequerySuggested()

The CommandManager only pays attention to certain conditions in determining when the command target has changed, such as change in keyboard focus. In situations where the CommandManager does not sufficiently determine a change in conditions that cause a command to not be able to execute, InvalidateRequerySuggested can be called to force the CommandManager to raise the RequerySuggested event.

The following example uses a DispatcherTimer to periodically call InvalidateRequerySuggested to force the CommandManager to raise the RequerySuggested event.

//  System.Windows.Threading.DispatcherTimer.Tick handler
//
//  Updates the current seconds display and calls
//  InvalidateRequerySuggested on the CommandManager to force 
//  the Command to raise the CanExecuteChanged event.
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
    // Updating the Label which displays the current second
    lblSeconds.Content = DateTime.Now.Second;

    // Forcing the CommandManager to raise the RequerySuggested event
    CommandManager.InvalidateRequerySuggested();
}

.NET Framework
Available since 3.0
Return to top
Show: