共用方式為


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只有在判斷命令目標何時變更時,才會注意某些條件,例如鍵盤焦點變更。 在 無法充分判斷導致命令無法執行的狀況變更的情況下 CommandManagerInvalidateRequerySuggested 可以呼叫 來強制 CommandManager 引發 RequerySuggested 事件。

適用於