Compartir a través de


CommandBinding.Executed Evento

Definición

Se produce cuando se ejecuta el comando asociado a este CommandBinding.

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

Ejemplos

En el ejemplo siguiente se crea un CommandBinding objeto que asigna un ExecutedRoutedEventHandler y un CanExecuteRoutedEventArgs controlador al 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)

A continuación se muestra el ExecutedRoutedEventHandler objeto que crea un MessageBox objeto cuando se ejecuta el comando .

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

Comentarios

Cuando se ejecuta , RoutedCommand genera el PreviewExecuted evento en el destino del comando. Si el PreviewExecuted evento no se controla, el Executed evento se genera en el destino del comando. Si el destino del comando tiene un CommandBinding para el comando específico, se llama al Executed controlador de .CommandBinding Si el destino del comando no tiene un CommandBinding para ese comando específico, el Executed evento propaga el árbol de elementos en busca de un elemento que tenga asociado CommandBinding al comando . Si no se encuentra , CommandBinding el comando no se controla.

Información sobre eventos enrutados

Campo identificador ExecutedEvent
Estrategia de enrutamiento Burbujeante
Delegado ExecutedRoutedEventHandler

Se aplica a

Consulte también