CanExecuteRoutedEventArgs.CanExecute Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy RoutedCommand skojarzone z tym zdarzeniem można wykonać na obiekcie docelowym polecenia.

public:
 property bool CanExecute { bool get(); void set(bool value); };
public bool CanExecute { get; set; }
member this.CanExecute : bool with get, set
Public Property CanExecute As Boolean

Wartość właściwości

true jeśli zdarzenie można wykonać na obiekcie docelowym polecenia; w przeciwnym razie , false. Wartość domyślna to false.

Przykłady

Poniższy przykład tworzy obiekt CanExecuteRoutedEventHandler , który zwraca wartość true tylko wtedy, gdy element docelowy polecenia jest kontrolką. Source Najpierw dane zdarzenia są rzutowania na element Control. Jeśli jest to wartość , CanExecute jest ustawiona Controlna true, w przeciwnym razie ustawiono wartość false.

// CanExecuteRoutedEventHandler that only returns true if
// the source is a control.
private void CanExecuteCustomCommand(object sender, 
    CanExecuteRoutedEventArgs e)
{
    Control target = e.Source as Control;
    
    if(target != null)
    {
        e.CanExecute = true;
    }
    else
    {
        e.CanExecute = false;
    }
}
' CanExecuteRoutedEventHandler that only returns true if
' the source is a control.
Private Sub CanExecuteCustomCommand(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
    Dim target As Control = TryCast(e.Source, Control)

    If target IsNot Nothing Then
        e.CanExecute = True
    Else
        e.CanExecute = False
    End If
End Sub

Uwagi

Wiele źródeł poleceń, takich jak MenuItem i Button, są wyłączone, gdy CanExecute jest false i włączone, gdy CanExecute parametr ma wartość true.

Dotyczy

Zobacz też