RoutedCommand.Execute(Object, IInputElement) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 명령 대상에서 실행합니다 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
명령 처리기 검색을 시작할 요소입니다.
- 특성
예외
예제
다음 예제는 샘플의 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 포함되지 않습니다. Execute 가 있는 개체를 PreviewExecuted 찾는 요소 트리를 통해 터널 및 거품을 발생시키는 이벤트 및 ExecutedCommandBinding이벤트를 발생합니다. for가 CommandBindingRoutedCommand 발견 ExecutedRoutedEventHandler 되면 연결된 CommandBinding 값이 호출됩니다. 이러한 처리기는 .를 수행하는 프로그래밍 논리를 RoutedCommand제공합니다.
PreviewExecuted 및 Executed 이벤트는 .에 CommandTarget발생합니다. 설정 CommandTarget 되지 않은 ICommandSourcePreviewExecutedExecuted 경우 키보드 포커스가 있는 요소에서 이벤트가 발생합니다.