Compartilhar via


CommandBinding.Executed Evento

Definição

Ocorre quando o comando associado a este CommandBinding é executado.

public:
 event System::Windows::Input::ExecutedRoutedEventHandler ^ Executed;
public event System.Windows.Input.ExecutedRoutedEventHandler Executed;
member this.Executed : System.Windows.Input.ExecutedRoutedEventHandler 
Public Custom Event Executed As ExecutedRoutedEventHandler 
Public Event Executed As ExecutedRoutedEventHandler 

Tipo de evento

Exemplos

O exemplo a seguir cria um CommandBinding que mapeia um ExecutedRoutedEventHandler e um CanExecuteRoutedEventArgs manipulador para o Open comando .

<Window.CommandBindings>
  <CommandBinding Command="ApplicationCommands.Open"
                  Executed="OpenCmdExecuted"
                  CanExecute="OpenCmdCanExecute"/>
</Window.CommandBindings>
// Creating CommandBinding and attaching an Executed and CanExecute handler
CommandBinding OpenCmdBinding = new CommandBinding(
    ApplicationCommands.Open,
    OpenCmdExecuted,
    OpenCmdCanExecute);

this.CommandBindings.Add(OpenCmdBinding);
' Creating CommandBinding and attaching an Executed and CanExecute handler
Dim OpenCmdBinding As New CommandBinding(ApplicationCommands.Open, AddressOf OpenCmdExecuted, AddressOf OpenCmdCanExecute)

Me.CommandBindings.Add(OpenCmdBinding)

O exemplo a seguir mostra o ExecutedRoutedEventHandler que cria um MessageBox quando o comando é executado.

void OpenCmdExecuted(object target, ExecutedRoutedEventArgs e)
{
    String command, targetobj;
    command = ((RoutedCommand)e.Command).Name;
    targetobj = ((FrameworkElement)target).Name;
    MessageBox.Show("The " + command +  " command has been invoked on target object " + targetobj);
}
Private Sub OpenCmdExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    Dim command, targetobj As String
    command = CType(e.Command, RoutedCommand).Name
    targetobj = CType(sender, FrameworkElement).Name
    MessageBox.Show("The " + command + " command has been invoked on target object " + targetobj)
End Sub

Comentários

Quando um RoutedCommand é executado, ele aciona o PreviewExecuted evento no destino do comando. Se o PreviewExecuted evento não for tratado, o Executed evento será gerado no destino do comando. Se o destino do comando tiver um CommandBinding para o comando específico, o Executed manipulador para isso CommandBinding será chamado. Se o destino do comando não tiver um CommandBinding para esse comando específico, o Executed evento aumentará a árvore de elementos procurando um elemento que tenha um CommandBinding associado ao comando. Se um CommandBinding não for encontrado, o comando não será manipulado.

Informações de evento encaminhado

Campo Identificador ExecutedEvent
Estratégia de roteamento Borbulhando
Delegar ExecutedRoutedEventHandler

Aplica-se a

Confira também