CanExecuteRoutedEventArgs.Command Właściwość

Definicja

Pobiera polecenie skojarzone z tym zdarzeniem.

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

Wartość właściwości

Polecenie. Chyba że polecenie jest poleceniem niestandardowym, zazwyczaj jest RoutedCommandto . Nie ma żadnej wartości domyślnej.

Przykłady

Poniższy przykład tworzy obiekt CanExecuteRoutedEventHandler , który obsługuje wiele poleceń. Command Jeśli właściwość jest równa Play poleceniu, a metoda IsPlaying zwraca falsewartość , CanExecute jest ustawiona na truewartość ; w przeciwnym razie CanExecute ustawiono wartość false. Command Jeśli właściwość jest równa Stop poleceniu, a metoda IsPlaying zwraca truewartość , CanExecute jest ustawiona na truewartość ; w przeciwnym razie CanExecute ustawiono wartość 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

Uwagi

Aby uzyskać więcej informacji na temat poleceń, zobacz Omówienie poleceń.

Dotyczy

Zobacz też