CommandBinding.Executed Evento

Definizione

Si verifica quando viene eseguito il comando associato a questo 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 evento

Esempio

Nell'esempio seguente viene creato un oggetto CommandBinding che esegue il mapping di un ExecutedRoutedEventHandler oggetto e di un CanExecuteRoutedEventArgs gestore 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)

Di seguito viene illustrato l'oggetto ExecutedRoutedEventHandler che crea un MessageBox oggetto quando viene eseguito il 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

Commenti

Quando un oggetto RoutedCommand viene eseguito, genera l'evento PreviewExecuted nella destinazione del comando. Se l'evento PreviewExecuted non viene gestito, l'evento Executed viene generato nella destinazione del comando. Se la destinazione del comando ha un CommandBinding oggetto per il comando specifico, viene chiamato il Executed gestore per tale CommandBinding comando. Se la destinazione del comando non dispone di un CommandBinding oggetto per tale comando specifico, l'evento Executed si adatta all'albero degli elementi cercando un elemento CommandBinding associato al comando. Se un oggetto CommandBinding non viene trovato, il comando non viene gestito.

Informazioni sugli eventi indirizzati

Item Value
Campo Identificatore ExecutedEvent
Strategia di routing Bubbling
Delegato ExecutedRoutedEventHandler

Si applica a

Vedi anche