ExecutedRoutedEventHandler 대리자

정의

관련된 연결된 이벤트뿐만 아니라 라우트된 이벤트 및 PreviewExecuted 라우트된 이벤트를 처리 Executed 할 메서드를 나타냅니다.

public delegate void ExecutedRoutedEventHandler(System::Object ^ sender, ExecutedRoutedEventArgs ^ e);
public delegate void ExecutedRoutedEventHandler(object sender, ExecutedRoutedEventArgs e);
type ExecutedRoutedEventHandler = delegate of obj * ExecutedRoutedEventArgs -> unit
Public Delegate Sub ExecutedRoutedEventHandler(sender As Object, e As ExecutedRoutedEventArgs)

매개 변수

sender
Object

이벤트 처리기가 연결된 개체입니다.

e
ExecutedRoutedEventArgs

이벤트 데이터입니다.

예제

다음은 명령이 실행될 때 대상에 시각적 속성을 설정하는 예제 ExecutedRoutedEventHandler 입니다. 이 예제에는 동일한 명령에 대한 명령도 포함됩니다 CanExecuteRoutedEventHandler .

// ExecutedRoutedEventHandler for the custom color command.
private void ColorCmdExecuted(object sender, ExecutedRoutedEventArgs e)
{
    Panel target = e.Source as Panel;
    if (target != null)
    {
        if (target.Background == Brushes.AliceBlue)
        {
            target.Background = Brushes.LemonChiffon;
        }
        else
        {
            target.Background = Brushes.AliceBlue;
        }
    }
}

// CanExecuteRoutedEventHandler for the custom color command.
private void ColorCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    if (e.Source is Panel)
    {
        e.CanExecute = true;
    }
    else
    {
        e.CanExecute = false;
    }
}
' ExecutedRoutedEventHandler for the custom color command.
Private Sub ColorCmdExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    Dim target As Panel = TryCast(e.Source, Panel)
    If target IsNot Nothing Then
        If target.Background Is Brushes.AliceBlue Then
            target.Background = Brushes.LemonChiffon
        Else
            target.Background = Brushes.AliceBlue
        End If

    End If
End Sub

' CanExecuteRoutedEventHandler for the custom color command.
Private Sub ColorCmdCanExecute(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
    If TypeOf e.Source Is Panel Then
        e.CanExecute = True
    Else
        e.CanExecute = False
    End If
End Sub

설명

이 대리자는 에 대한 구현 논리를 RoutedCommand포함합니다. 명령에서 구현 논리를 분리하면 다른 소스 및 형식에서 명령을 호출할 수 있으며 명령 논리의 중앙 집중화를 사용하도록 설정합니다.

이 대리자는 명령 인프라의 대부분을 구현하는 클래스에 CommandManager 연결된 이벤트에도 사용됩니다.CommandManager.ExecutedCommandManager.PreviewExecuted 그러나 가장 실용적인 처리기는 수준에서 작업 CommandManager 하는 것이 아니라 특정 CommandBinding이벤트의 이벤트를 처리 Executed 합니다.

내에서 ExecutedRoutedEventArgs다음 속성은 일반적으로 실행된 명령에서 발생하는 라우트된 이벤트에 대한 이벤트 처리기를 작성할 때 관심이 있습니다.

  • Source 는 명령이 실행된 대상을 보고합니다. 명령이 실행되면 라우트된 이벤트 용어에서 더 일반적으로 라우트된 이벤트를 발생시킨 개체로 생각할 Source 수도 있습니다.

  • Command 는 실행된 명령을 보고합니다. 이 속성은 명령 바인딩을 사용 하 고 잠재적으로 여러 명령을 처리 하는 처리기를 작성 하는 경우에 유용 합니다.

  • Parameter 는 실행 중인 명령에 의해 전달된 명령별 매개 변수를 보고합니다. 모든 명령이 명령별 매개 변수를 사용하거나 기대하지는 않습니다.

  • Handled 는 실행된 명령에서 생성된 라우트된 이벤트가 경로를 따라 다른 요소에 의해 이미 처리되었는지 여부를 보고합니다. 라우트된 이벤트 처리기의 경우 설정할 Handledtrue이벤트를 처리할 때 의미 있는 작업을 수행하는 처리기를 사용하는 것이 좋습니다. 이렇게 하면 이벤트에 대한 일반적인 처리기가 경로를 따라 이벤트를 다시 처리하지 못하게 됩니다. 라우트된 이벤트를 처리하는 방법에 대한 자세한 내용은 라우트 된 이벤트를 처리됨으로 표시 및 클래스 처리를 참조하세요.

또한 이 대리자는 명령 인프라의 대부분을 구현하는 클래스에 CommandManager 연결된 이벤트인 처리기 및 CommandManager.PreviewExecutedEvent해당 처리기를 CommandManager.Executed 나타냅니다. 그러나 가장 실용적인 처리기는 수준에서 작업 CommandManager 하는 것이 아니라 특정 CommandBinding이벤트의 이벤트를 처리 Executed 합니다.

명령에 대한 자세한 내용은 명령 개요를 참조하세요.

확장명 메서드

Name Description
GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보