Bagikan melalui


CanExecuteRoutedEventArgs.Command Properti

Definisi

Mendapatkan perintah yang terkait dengan kejadian ini.

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

Nilai Properti

Perintah. Kecuali perintah adalah perintah kustom, ini umumnya adalah RoutedCommand. Tidak ada nilai default.

Contoh

Contoh berikut membuat yang CanExecuteRoutedEventHandler menangani beberapa perintah. Command Jika properti sama dengan Play perintah dan metode IsPlaying mengembalikan false, CanExecute diatur ke true; jika tidak, CanExecute diatur ke false. Command Jika properti sama dengan Stop perintah dan metode IsPlaying mengembalikan true, CanExecute diatur ke true; jika tidak, CanExecute diatur ke 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

Keterangan

Untuk informasi selengkapnya tentang perintah, lihat Gambaran Umum Perintah.

Berlaku untuk

Lihat juga