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

属性值

ICommand

命令。 如果该命令不是自定义命令,则此值通常为 RoutedCommand。 无默认值。

示例

以下示例创建一个 CanExecuteRoutedEventHandler 处理多个命令的 。 Command如果 属性等于 命令,Play并且方法IsPlaying返回 falseCanExecute则 设置为 true;否则, CanExecute 设置为 falseCommand如果 属性等于 命令,Stop并且方法IsPlaying返回 trueCanExecute则 设置为 true;否则, CanExecute 设置为 false

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

注解

有关命令的详细信息,请参阅命令概述

适用于

另请参阅