CommandBinding.CanExecute Événement

Définition

Se produit lorsque la commande associée CommandBinding lance une vérification pour déterminer si la commande peut être exécutée sur la cible de commande.

public:
 event System::Windows::Input::CanExecuteRoutedEventHandler ^ CanExecute;
public event System.Windows.Input.CanExecuteRoutedEventHandler CanExecute;
member this.CanExecute : System.Windows.Input.CanExecuteRoutedEventHandler 
Public Custom Event CanExecute As CanExecuteRoutedEventHandler 
Public Event CanExecute As CanExecuteRoutedEventHandler 

Type d'événement

Exemples

L’exemple suivant crée un CommandBinding mappage d’un ExecutedRoutedEventHandler gestionnaire et d’un CanExecuteRoutedEventArgs gestionnaire à la Open commande.

<Window.CommandBindings>
  <CommandBinding Command="ApplicationCommands.Open"
                  Executed="OpenCmdExecuted"
                  CanExecute="OpenCmdCanExecute"/>
</Window.CommandBindings>
// Creating CommandBinding and attaching an Executed and CanExecute handler
CommandBinding OpenCmdBinding = new CommandBinding(
    ApplicationCommands.Open,
    OpenCmdExecuted,
    OpenCmdCanExecute);

this.CommandBindings.Add(OpenCmdBinding);
' Creating CommandBinding and attaching an Executed and CanExecute handler
Dim OpenCmdBinding As New CommandBinding(ApplicationCommands.Open, AddressOf OpenCmdExecuted, AddressOf OpenCmdCanExecute)

Me.CommandBindings.Add(OpenCmdBinding)

L’exemple suivant montre les CanExecuteRoutedEventHandler ensembles CanExecute sur true.

void OpenCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    e.CanExecute = true;
}
Private Sub OpenCmdCanExecute(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
    e.CanExecute = True
End Sub

Remarques

Lorsque la CanExecute méthode sur un RoutedCommand est appelée, l’événement PreviewCanExecute est déclenché sur la cible de commande. Si l’événement n’est pas géré, l’événement CanExecute est déclenché. Si la cible de commande a une CommandBinding pour la commande, le CanExecute gestionnaire pour celui-ci CommandBinding est appelé. Si la cible de commande n’a pas de CommandBinding commande, l’événement CanExecute fait apparaître l’arborescence d’éléments qui recherche un CommandBinding élément associé à la commande.

Informations sur les événements routés

Élément Valeur
Champ d’identificateur CanExecuteEvent
Stratégie de routage Bouillonnant
Déléguer CanExecuteRoutedEventHandler

S’applique à

Voir aussi