RoutedCommand.Execute(Object, IInputElement) RoutedCommand.Execute(Object, IInputElement) RoutedCommand.Execute(Object, IInputElement) RoutedCommand.Execute(Object, IInputElement) Method

定義

現在のコマンドの対象で RoutedCommand を実行します。Executes the RoutedCommand on the current command target.

public:
 void Execute(System::Object ^ parameter, System::Windows::IInputElement ^ target);
[System.Security.SecurityCritical]
public void Execute (object parameter, System.Windows.IInputElement target);
member this.Execute : obj * System.Windows.IInputElement -> unit
Public Sub Execute (parameter As Object, target As IInputElement)

パラメーター

parameter
Object Object Object Object

ハンドラーに渡されるユーザー定義パラメーター。User defined parameter to be passed to the handler.

target
IInputElement IInputElement IInputElement IInputElement

コマンド ハンドラーの検索を開始する要素。Element at which to begin looking for command handlers.

例外

次の例は、サンプルのICommandSourceカスタム実装からのものです。The following example is from a custom implementation of ICommandSource sample.

this.Commandこの例では、のICommandSourceCommand プロパティがです。this.Command in this example is the Command property on the ICommandSource. コマンドが null でない場合、コマンドはにRoutedCommandキャストされます。If the command is not null, the command is cast to a RoutedCommand. RoutedCommandの場合、 Executeメソッドが呼び出され、 CommandTargetとが渡されます。 CommandParameterIf it is a RoutedCommand, then the Execute method is called passing the CommandTarget and the CommandParameter. RoutedCommandコマンドがでない場合は、 ICommandExecuteキャストされ、メソッドがを渡しCommandParameterて呼び出されます。If the command is not a RoutedCommand, it is cast to an ICommand and the Execute method is called passing the CommandParameter.

// If Command is defined, moving the slider will invoke the command;
// Otherwise, the slider will behave normally.
protected override void OnValueChanged(double oldValue, double newValue)
{
    base.OnValueChanged(oldValue, newValue);

    if (this.Command != null)
    {
        RoutedCommand command = Command as RoutedCommand;

        if (command != null)
        {
            command.Execute(CommandParameter, CommandTarget);
        }
        else
        {
            ((ICommand)Command).Execute(CommandParameter);
        }
    }
}
' If Command is defined, moving the slider will invoke the command;
' Otherwise, the slider will behave normally.
Protected Overrides Sub OnValueChanged(ByVal oldValue As Double, ByVal newValue As Double)
    MyBase.OnValueChanged(oldValue, newValue)

    If Me.Command IsNot Nothing Then
        Dim command As RoutedCommand = TryCast(Me.Command, RoutedCommand)

        If command IsNot Nothing Then
            command.Execute(CommandParameter, CommandTarget)
        Else
            CType(Me.Command, ICommand).Execute(CommandParameter)
        End If
    End If
End Sub

注釈

を実行RoutedCommandする実際のロジックは、 Executeメソッドには含まれていません。The actual logic that executes the RoutedCommand is not contained in the Execute methods. ExecuteイベントとPreviewExecuted Executedイベントを発生させます。このイベントは、要素ツリーを通じて、 CommandBindingを持つオブジェクトを検索します。Execute raises the PreviewExecuted and Executed events, which tunnel and bubble through the element tree looking for an object with a CommandBinding. のが見つかった場合CommandBindingは、にアタッチされたが呼び出されます。ExecutedRoutedEventHandler RoutedCommand CommandBindingIf a CommandBinding for that RoutedCommand is found, then the ExecutedRoutedEventHandler attached to CommandBinding is called. これらのハンドラーは、 RoutedCommandを実行するプログラミングロジックを提供します。These handlers supply the programming logic that performs the RoutedCommand.

イベントとイベントExecutedがで発生します。CommandTarget PreviewExecutedThe PreviewExecuted and Executed events are raised on the CommandTarget. がに設定されていないExecuted場合PreviewExecuted、およびイベントは、キーボードフォーカスを持つ要素で発生します。 ICommandSource CommandTargetIf the CommandTarget is not set on the ICommandSource, the PreviewExecuted and Executed events are raised on the element with keyboard focus.

適用対象