共用方式為


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且 方法IsPlayingfalse回 ,CanExecute則會設定為 trueCanExecute否則會設定為 falseCommand如果 屬性等於 命令,Stop且 方法IsPlayingtrue回 ,CanExecute則會設定為 trueCanExecute否則會設定為 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

備註

如需命令的詳細資訊,請參閱 命令概觀

適用於

另請參閱