RoutedCommand.Execute(Object, IInputElement) 메서드

정의

현재 명령 대상에서 RoutedCommand를 실행합니다.

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

매개 변수

parameter
Object

처리기에 전달되는 사용자 정의 매개 변수입니다.

target
IInputElement

명령 처리기를 찾을 요소입니다.

특성

예외

targetUIElement 또는 ContentElement가 아닌 경우

예제

다음 예제는 샘플의 ICommandSource 사용자 지정 구현입니다.

this.Command 이 예제에서는 의 Command 속성입니다 ICommandSource. 명령이 null이 아니면 명령이 로 RoutedCommand캐스팅됩니다. 가 이 RoutedCommand면 메서드를 Execute 호출하여 및 를 CommandTarget 전달합니다 CommandParameter. 명령이 이 아닌 경우 으로 RoutedCommand캐스팅 ICommand 되고 메서드가 Execute 를 전달하도록 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 포함되지 않습니다. ExecutePreviewExecutedExecuted 이벤트를 발생시키는데, 이 이벤트는 가 있는 개체를 찾는 요소 트리를 통해 터널과 버블을 만듭니다 CommandBinding. CommandBinding 에 대한 가 RoutedCommand 발견 ExecutedRoutedEventHandler 되면 에 연결된 CommandBinding 가 호출됩니다. 이러한 처리기는 를 수행하는 프로그래밍 논리를 RoutedCommand제공합니다.

PreviewExecutedExecuted 이벤트는 에서 CommandTarget발생합니다. 가 CommandTargetICommandSourcePreviewExecuted 설정되지 않은 경우 및 Executed 이벤트는 키보드 포커스가 있는 요소에서 발생합니다.

적용 대상