共用方式為


CommandBinding.Executed 事件

定義

與此 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 

事件類型

範例

下列範例會建立 ,CommandBinding將 和 CanExecuteRoutedEventArgs 處理程式對應ExecutedRoutedEventHandlerOpen 命令。

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

以下顯示 ExecutedRoutedEventHandler 執行命令時所建立 MessageBox 的 。

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

備註

RoutedCommand執行時,它會在命令目標上引發 PreviewExecuted 事件。 PreviewExecuted如果未處理事件,則會Executed在命令目標上引發事件。 如果命令目標具有 CommandBinding 特定命令的 ,則會 Executed 呼叫該命令 CommandBinding 的處理程式。 如果命令目標沒有 CommandBinding 該特定命令的 ,事件 Executed 就會向上反升元素樹狀結構,以搜尋與 CommandBinding 命令相關聯的專案。 CommandBinding如果找不到 ,則不會處理命令。

路由事件資訊

標識元欄位 ExecutedEvent
路由策略 鼓 泡
代理人 ExecutedRoutedEventHandler

適用於

另請參閱