CommandManager.AddExecutedHandler Yöntem

Tanım

Belirtilen ExecutedRoutedEventHandler öğesini belirtilen öğeye ekler.

public:
 static void AddExecutedHandler(System::Windows::UIElement ^ element, System::Windows::Input::ExecutedRoutedEventHandler ^ handler);
public static void AddExecutedHandler (System.Windows.UIElement element, System.Windows.Input.ExecutedRoutedEventHandler handler);
static member AddExecutedHandler : System.Windows.UIElement * System.Windows.Input.ExecutedRoutedEventHandler -> unit
Public Shared Sub AddExecutedHandler (element As UIElement, handler As ExecutedRoutedEventHandler)

Parametreler

element
UIElement

Eklenecek handler öğe.

handler
ExecutedRoutedEventHandler

Yürütülen işleyici.

Özel durumlar

element veya handler şeklindedir null.

Örnekler

Aşağıdaki örnek, bir CanExecuteRoutedEventHandler ve ExecutedRoutedEventHandler oluşturur ve bunları komutun komut kaynağı olan bir Button öğesine Help ekler.

İlk olarak, Button komutu oluşturulur ve komutuyla ilişkilendirilir Help .

<Button Command="ApplicationCommands.Help"
        Name="helpButton">Help</Button>

CanExecuteRoutedEventHandler Ardından ve ExecutedRoutedEventHandler oluşturulur.

private void HelpCmdExecuted(object sender, ExecutedRoutedEventArgs e)
{
    // OpenHelpFile opens the help file
    OpenHelpFile();
}
Private Sub HelpCmdExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    ' OpenHelpFile opens the help file
    OpenHelpFile()
End Sub
private void HelpCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    // HelpFilesExists() determines if the help file exists
    if (HelpFileExists() == true)
    {
        e.CanExecute = true;
    }
    else
    {
        e.CanExecute = false;
    }
}
Private Sub HelpCmdCanExecute(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
    ' HelpFilesExists() determines if the help file exists
    If HelpFileExists() = True Then
        e.CanExecute = True
    Else
        e.CanExecute = False
    End If
End Sub

Son olarak, işleyiciler ve AddExecutedHandlerkullanılarak AddCanExecuteHandler öğesine Button eklenir.

CommandManager.AddExecutedHandler(helpButton, HelpCmdExecuted);
CommandManager.AddCanExecuteHandler(helpButton, HelpCmdCanExecute);
CommandManager.AddExecutedHandler(helpButton, AddressOf HelpCmdExecuted)
CommandManager.AddCanExecuteHandler(helpButton, AddressOf HelpCmdCanExecute)

Şunlara uygulanır

Ayrıca bkz.