CanExecuteRoutedEventArgs.Command Egenskap

Definition

Hämtar kommandot som är associerat med den här händelsen.

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

Egenskapsvärde

Kommandot . Om kommandot inte är ett anpassat kommando är detta vanligtvis en RoutedCommand. Det finns inget standardvärde.

Exempel

I följande exempel skapas en CanExecuteRoutedEventHandler som hanterar flera kommandon. Om egenskapen Command är lika med Play kommandot och metoden IsPlaying returnerar false, CanExecute anges till true. Annars CanExecute är den inställd på false. Om egenskapen Command är lika med Stop kommandot och metoden IsPlaying returnerar true, CanExecute anges till true. Annars CanExecute är den inställd på false.

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

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

        if (command == MediaCommands.Stop)
        {
            if (IsPlaying())
            {
                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

Kommentarer

Mer information om kommandon finns i Översikt över kommandon.

Gäller för

Se även