CommandManager.InvalidateRequerySuggested CommandManager.InvalidateRequerySuggested CommandManager.InvalidateRequerySuggested CommandManager.InvalidateRequerySuggested Method

定義

CommandManager に、RequerySuggested イベントを強制的に発生させます。Forces the CommandManager to raise the RequerySuggested event.

public:
 static void InvalidateRequerySuggested();
public static void InvalidateRequerySuggested ();
static member InvalidateRequerySuggested : unit -> unit
Public Shared Sub InvalidateRequerySuggested ()

次の例ではDispatcherTimer 、を使用InvalidateRequerySuggestedして、 CommandManagerRequerySuggestedイベントを発生させるためにを定期的に呼び出します。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();
}
'  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 Sub dispatcherTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
    ' Updating the Label which displays the current second
    lblSeconds.Content = Date.Now.Second

    ' Forcing the CommandManager to raise the RequerySuggested event
    CommandManager.InvalidateRequerySuggested()
End Sub

注釈

CommandManagerは、キーボードフォーカスの変更など、コマンドターゲットがいつ変更されたかを判断する際に、特定の条件に注意してください。The CommandManager only pays attention to certain conditions in determining when the command target has changed, such as change in keyboard focus. が、コマンドをCommandManager InvalidateRequerySuggested実行できない原因となる条件の変化を十分に判断できない場合は、を呼び出して、 CommandManagerRequerySuggestedイベントを発生させることができます。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.

適用対象