RoutedCommand.Execute(Object, IInputElement) Metódus

Definíció

Végrehajtja az RoutedCommand aktuális parancscélt.

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éterek

parameter
Object

A kezelőnek átadni kívánt felhasználó által megadott paraméter.

target
IInputElement

Elem, amelynél a parancskezelők keresése elkezdhető.

Attribútumok

Kivételek

Példák

Az alábbi példa a minta egyéni implementációjából származik ICommandSource .

this.Command ebben a példában a Command tulajdonság a ICommandSource. Ha a parancs nem null értékű, a parancs egy RoutedCommand. Ha ez egy RoutedCommand, akkor a Execute metódust úgy nevezzük, hogy átadja az CommandTarget és a CommandParameter. Ha a parancs nem egy RoutedCommand, akkor a rendszer egy ICommand parancsra irányítja, és a Execute metódust a rendszer átadja a CommandParameterparancsnak.

// 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

Megjegyzések

A tényleges logikát, amely végrehajtja, RoutedCommand nem tartalmazza a Execute metódusok. Execute azokat az PreviewExecutedExecuted eseményeket emeli ki, amelyek alagutat és buborékot képeznek az elemfán, és egy objektumot keresnek egy CommandBinding. Ha egy CommandBinding ilyen RoutedCommand található, akkor a rendszer meghívja a ExecutedRoutedEventHandler csatolt elemet CommandBinding . Ezek a kezelők biztosítják a programozási logikát, amely végrehajtja a RoutedCommand.

A PreviewExecuted rendszer Executed az eseményeket a CommandTarget. Ha a CommandTarget beállítás nincs beállítva, ICommandSourcea rendszer a PreviewExecutedExecuted billentyűzetfókuszú elemen emeli ki az eseményeket.

A következőre érvényes: