Bagikan melalui


CommandBinding.Executed Kejadian

Definisi

Terjadi ketika perintah yang terkait dengan ini CommandBinding dijalankan.

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 

Jenis Acara

Contoh

Contoh berikut membuat CommandBinding yang memetakan dan ExecutedRoutedEventHandlerCanExecuteRoutedEventArgs handler ke Open perintah .

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

Berikut ini menunjukkan ExecutedRoutedEventHandler yang membuat MessageBox saat perintah dijalankan.

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

Keterangan

RoutedCommand Saat dijalankan, ini akan menaikkan PreviewExecuted peristiwa pada target perintah. PreviewExecuted Jika peristiwa tidak ditangani, Executed peristiwa akan dinaikkan pada target perintah. Jika target perintah memiliki CommandBinding untuk perintah tertentu, Executed handler untuk itu CommandBinding dipanggil. Jika target perintah tidak memiliki CommandBinding untuk perintah Executed tertentu, peristiwa menggelembung ke atas pohon elemen yang mencari elemen yang memiliki CommandBinding yang terkait dengan perintah. CommandBinding Jika tidak ditemukan, perintah tidak ditangani.

Informasi Peristiwa Yang Dirutekan

Bidang pengidentifikasi ExecutedEvent
Strategi perutean Menggelegak
Delegasikan ExecutedRoutedEventHandler

Berlaku untuk

Lihat juga