Bagikan melalui


CommandManager.InvalidateRequerySuggested Metode

Definisi

CommandManager Memaksa untuk meningkatkan RequerySuggested peristiwa.

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

Contoh

Contoh berikut menggunakan DispatcherTimer panggilan InvalidateRequerySuggested untuk secara berkala untuk memaksa CommandManager menaikkan RequerySuggested peristiwa.

//  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

Keterangan

Satu-satunya CommandManager memperhatikan kondisi tertentu dalam menentukan kapan target perintah telah berubah, seperti perubahan fokus keyboard. Dalam situasi di mana CommandManager tidak cukup menentukan perubahan kondisi yang menyebabkan perintah tidak dapat dijalankan, InvalidateRequerySuggested dapat dipanggil untuk memaksa CommandManager untuk menaikkan RequerySuggested peristiwa.

Berlaku untuk