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 

イベントの種類

次の例では、ExecutedRoutedEventHandlerCanExecuteRoutedEventArgs ハンドラーを Open コマンドにマップするCommandBindingを作成します。

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

コマンドの実行時にMessageBoxを作成するExecutedRoutedEventHandlerを次に示します。

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がある場合は、そのCommandBindingExecuted ハンドラーが呼び出されます。 コマンド ターゲットにその特定のコマンドの CommandBinding がない場合、 Executed イベントは、コマンドに関連付けられた CommandBinding を持つ要素を検索する要素ツリーをバブル アップします。 CommandBindingが見つからない場合、コマンドは処理されません。

ルーティング イベント情報

品目 価値
識別子フィールド ExecutedEvent
ルーティング戦略 バブル
代理人 ExecutedRoutedEventHandler

適用対象

こちらもご覧ください