RoutedCommand.Execute(Object, IInputElement) Metoda

Definice

RoutedCommand Spustí aktuální cíl příkazu.

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)

Parametry

parameter
Object

Uživatelem definovaný parametr, který se má předat obslužné rutině.

target
IInputElement

Prvek, na kterém začít hledat obslužné rutiny příkazů.

Atributy

Výjimky

Příklady

Následující příklad pochází z vlastní implementace ukázky ICommandSource .

this.Commandv tomto příkladu je Command vlastnost .ICommandSource Pokud příkaz není null, příkaz se přetypuje na hodnotu RoutedCommand. Pokud je RoutedCommandto , pak Execute metoda se nazývá předávání CommandTarget a CommandParameter. Pokud příkaz není RoutedCommand, je přetypován na a ICommandExecute metoda je volána předání 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

Poznámky

Skutečná logika, která provede, RoutedCommand není obsažena v Execute metodách. Execute PreviewExecuted vyvolá a Executed události, které tunelem a bublinou prochází strom elementu, který hledá objekt s objektem CommandBinding. Pokud je nalezena CommandBinding hodnota, RoutedCommand volá se ExecutedRoutedEventHandler připojený k CommandBinding němu. Tyto obslužné rutiny poskytují programovací logiku RoutedCommand, která provádí .

Události PreviewExecuted a Executed události jsou vyvolány na CommandTarget. Pokud není nastaven na CommandTarget , ICommandSourcePreviewExecuted a Executed události jsou vyvolány na prvku s fokusem klávesnice.

Platí pro