CommandManager.InvalidateRequerySuggested メソッド

定義

CommandManager イベントを強制的に発生させるRequerySuggested

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

次の例では、 DispatcherTimer を使用して定期的に InvalidateRequerySuggested を呼び出し、 CommandManagerRequerySuggested イベントを強制的に発生させます。

//  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は、キーボード フォーカスの変更など、コマンド ターゲットがいつ変更されたかを判断する際の特定の条件にのみ注意を払います。 CommandManagerがコマンドを実行できない状態の変化を十分に判断できない場合は、InvalidateRequerySuggestedを呼び出して、CommandManagerRequerySuggested イベントを強制的に発生させることができます。

適用対象