CommandManager.InvalidateRequerySuggested 方法

定義

迫使他們CommandManager提高事件。RequerySuggested

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

範例

以下範例使用 以 DispatcherTimer 定期呼叫 InvalidateRequerySuggested ,強制 事件 CommandManager 起訴 RequerySuggested

//  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 可以呼叫 強制 啟動 CommandManager 事件 RequerySuggested

適用於