RoutedCommand.Execute(Object, IInputElement) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Exécute la RoutedCommand cible de commande actuelle.
public:
void Execute(System::Object ^ parameter, System::Windows::IInputElement ^ target);
[System.Security.SecurityCritical]
public void Execute(object parameter, System.Windows.IInputElement target);
public void Execute(object parameter, System.Windows.IInputElement target);
[<System.Security.SecurityCritical>]
member this.Execute : obj * System.Windows.IInputElement -> unit
member this.Execute : obj * System.Windows.IInputElement -> unit
Public Sub Execute (parameter As Object, target As IInputElement)
Paramètres
- parameter
- Object
Paramètre défini par l’utilisateur à passer au gestionnaire.
- target
- IInputElement
Élément auquel commencer la recherche de gestionnaires de commandes.
- Attributs
Exceptions
target n’est pas un UIElement ou ContentElement.
Exemples
L’exemple suivant provient d’une implémentation personnalisée d’un ICommandSource exemple.
this.Command dans cet exemple est la propriété Command sur le ICommandSource. Si la commande n’est pas null, la commande est convertie en RoutedCommand. S’il s’agit d’un RoutedCommand, la Execute méthode est appelée en passant le CommandTarget et le CommandParameter. Si la commande n’est pas un RoutedCommand, elle est convertie en un ICommand et la Execute méthode est appelée en passant le CommandParameter.
// If Command is defined, moving the slider will invoke the command;
// Otherwise, the slider will behave normally.
protected override void OnValueChanged(double oldValue, double newValue)
{
base.OnValueChanged(oldValue, newValue);
if (this.Command != null)
{
RoutedCommand command = Command as RoutedCommand;
if (command != null)
{
command.Execute(CommandParameter, CommandTarget);
}
else
{
((ICommand)Command).Execute(CommandParameter);
}
}
}
' If Command is defined, moving the slider will invoke the command;
' Otherwise, the slider will behave normally.
Protected Overrides Sub OnValueChanged(ByVal oldValue As Double, ByVal newValue As Double)
MyBase.OnValueChanged(oldValue, newValue)
If Me.Command IsNot Nothing Then
Dim command As RoutedCommand = TryCast(Me.Command, RoutedCommand)
If command IsNot Nothing Then
command.Execute(CommandParameter, CommandTarget)
Else
CType(Me.Command, ICommand).Execute(CommandParameter)
End If
End If
End Sub
Remarques
La logique réelle qui exécute le RoutedCommand fichier n’est pas contenue dans les Execute méthodes. Execute déclenche les PreviewExecuted événements, Executed qui tunnel et bullent dans l’arborescence d’éléments à la recherche d’un objet avec un CommandBinding. Si un CommandBinding pour cela RoutedCommand est trouvé, le ExecutedRoutedEventHandler joint à CommandBinding est appelé. Ces gestionnaires fournissent la logique de programmation qui effectue le RoutedCommand.
Les PreviewExecuted événements et Executed les événements sont déclenchés sur le CommandTarget. Si le CommandTarget paramètre n’est pas défini sur le ICommandSource, les PreviewExecuted événements et Executed les événements sont déclenchés sur l’élément avec le focus clavier.