CanExecuteRoutedEventArgs.CanExecute Propriedade

Definição

Recebe ou define um valor que indica se o RoutedCommand evento associado a este evento pode ser executado no alvo do comando.

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

Valor de Propriedade

true se o evento puder ser executado no alvo de comando; caso contrário, false. O valor predefinido é false.

Exemplos

O exemplo seguinte cria um CanExecuteRoutedEventHandler que só retorna verdadeiro se o alvo do comando for um controlo. Primeiro, os Source dados do evento são lançados para um Control. Se for um Control, é definido como true; caso contrário, é definido como falseCanExecute .

// 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

Observações

Muitas fontes de comandos, como MenuItem e , são desativadas quando CanExecute é false e ativadas quando é CanExecutetrueButton.

Aplica-se a

Ver também