Afficher en anglais

Partage via


CommandBinding.CanExecute Événement

Définition

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

C#
public event System.Windows.Input.CanExecuteRoutedEventHandler CanExecute;

Type d'événement

Exemples

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

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

this.CommandBindings.Add(OpenCmdBinding);

L’exemple suivant montre qui définit CanExecute sur CanExecuteRoutedEventHandlertrue.

C#
void OpenCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    e.CanExecute = true;
}

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 un CommandBinding pour la commande, le CanExecute gestionnaire pour celui-ci CommandBinding est appelé. Si la cible de commande n’a CommandBinding pas de CommandBinding pour la commande, l’événement CanExecute s’affiche dans l’arborescence d’éléments à la recherche d’un élément associé à la commande.

Informations sur les événements acheminés

Champ Identificateur CanExecuteEvent
Stratégie de routage Bouillonnant
Délégué CanExecuteRoutedEventHandler

S’applique à

Produit Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Voir aussi