RoutedCommand.Execute(Object, IInputElement) Método

Definición

Ejecuta en RoutedCommand el destino de comando actual.

public:
 void Execute(System::Object ^ parameter, System::Windows::IInputElement ^ target);
[System.Security.SecurityCritical]
public void Execute(object parameter, System.Windows.IInputElement target);
[<System.Security.SecurityCritical>]
member this.Execute : obj * System.Windows.IInputElement -> unit
Public Sub Execute (parameter As Object, target As IInputElement)

Parámetros

parameter
Object

Parámetro definido por el usuario que se va a pasar al controlador.

target
IInputElement

Elemento en el que se comienza a buscar controladores de comandos.

Atributos

Excepciones

Ejemplos

El ejemplo siguiente procede de una implementación personalizada de ejemplo ICommandSource .

this.Commanden este ejemplo, es la propiedad Command de .ICommandSource Si el comando no es null, el comando se convierte en .RoutedCommand Si es , RoutedCommandse llama al Execute método pasando y CommandTarget .CommandParameter Si el comando no es , RoutedCommandse convierte en y ICommand se llama al Execute método pasando el 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

Comentarios

La lógica real que ejecuta no RoutedCommand está contenida en los Execute métodos . Executegenera los PreviewExecuted eventos y Executed , que tuneliza y propagan por el árbol de elementos buscando un objeto con .CommandBinding Si se encuentra un CommandBinding para el que RoutedCommand se encuentra, ExecutedRoutedEventHandler se llama al adjunto a CommandBinding . Estos controladores proporcionan la lógica de programación que realiza .RoutedCommand

Los PreviewExecuted eventos y Executed se generan en .CommandTarget CommandTarget Si no se establece en ICommandSource, los PreviewExecuted eventos y Executed se generan en el elemento con foco de teclado.

Se aplica a