Share via


CanExecuteRoutedEventArgs.Command 속성

정의

이 이벤트와 연결된 명령을 가져옵니다.

public:
 property System::Windows::Input::ICommand ^ Command { System::Windows::Input::ICommand ^ get(); };
public System.Windows.Input.ICommand Command { get; }
member this.Command : System.Windows.Input.ICommand
Public ReadOnly Property Command As ICommand

속성 값

명령입니다. 명령이 사용자 지정 명령이 아닌 경우에는 일반적으로 RoutedCommand입니다. 기본값은 없습니다.

예제

다음 예제에서는 여러 명령을 처리하는 을 만듭니다 CanExecuteRoutedEventHandler . 속성이 Command 명령과 같 Play 고 메서드 IsPlaying 가 를 CanExecute 반환false하면 이 로 true설정되고, 그렇지 않으면 가 CanExecutefalse설정됩니다. 속성이 Command 명령과 같 Stop 고 메서드 IsPlaying 가 를 CanExecute 반환true하면 이 로 true설정되고, 그렇지 않으면 가 CanExecutefalse설정됩니다.

private void CanExecuteDisplayCommand(object sender,
    CanExecuteRoutedEventArgs e)
{
    RoutedCommand command = e.Command as RoutedCommand;

    if (command != null)
    {
        if (command == MediaCommands.Play)
        {
            if (IsPlaying() == false)
            {
                e.CanExecute = true;
            }
            else
            {
                e.CanExecute = false;
            }
        }

        if (command == MediaCommands.Stop)
        {
            if (IsPlaying() == true)
            {
                e.CanExecute = true;
            }
            else
            {
                e.CanExecute = false;
            }
        }
    }
}
Private Sub CanExecuteDisplayCommand(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
    Dim command As RoutedCommand = TryCast(e.Command, RoutedCommand)

    If command IsNot Nothing Then
        If command Is MediaCommands.Play Then
            If IsPlaying() = False Then
                e.CanExecute = True
            Else
                e.CanExecute = False
            End If
        End If

        If command Is MediaCommands.Stop Then
            If IsPlaying() = True Then
                e.CanExecute = True
            Else
                e.CanExecute = False
            End If
        End If
    End If
End Sub

설명

명령에 대 한 자세한 내용은 참조는 명령 개요합니다.

적용 대상

추가 정보