RoutedCommand.Execute(Object, IInputElement) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Esegue l'oggetto RoutedCommand nella destinazione del comando corrente.
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)
Parametri
- parameter
- Object
Parametro definito dall'utente da passare al gestore.
- target
- IInputElement
Elemento in corrispondenza del quale iniziare a cercare i gestori dei comandi.
- Attributi
Eccezioni
target non è o UIElementContentElement.
Esempio
L'esempio seguente proviene da un'implementazione personalizzata di ICommandSource esempio.
this.Command in questo esempio è la proprietà Command di ICommandSource. Se il comando non è Null, viene eseguito il cast del comando a un oggetto RoutedCommand. Se è un RoutedCommandoggetto , il Execute metodo viene chiamato passando CommandTarget e .CommandParameter Se il comando non è un RoutedCommand, viene eseguito il cast a un ICommand e il Execute metodo viene chiamato passando .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
Commenti
La logica effettiva che esegue l'oggetto RoutedCommand non è contenuta nei Execute metodi . Execute genera gli PreviewExecuted eventi e Executed che eseguono il tunneling e la bolla attraverso l'albero degli elementi alla ricerca di un oggetto con un oggetto CommandBinding. Se viene trovato un CommandBinding oggetto per , RoutedCommand viene chiamato l'oggetto ExecutedRoutedEventHandler associato a CommandBinding . Questi gestori forniscono la logica di programmazione che esegue .RoutedCommand
Gli PreviewExecuted eventi e Executed vengono generati nell'oggetto CommandTarget. Se l'oggetto CommandTarget non è impostato su ICommandSource, gli PreviewExecuted eventi e Executed vengono generati sull'elemento con lo stato attivo della tastiera.