RoutedCommand.Execute(Object, IInputElement) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
RoutedCommand Kör på det aktuella kommandomålet.
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)
Parametrar
- parameter
- Object
Användardefinierad parameter som ska skickas till hanteraren.
- target
- IInputElement
Element där du kan börja leta efter kommandohanterare.
- Attribut
Undantag
target är inte en UIElement eller ContentElement.
Exempel
Följande exempel är från en anpassad implementering av ICommandSource exempel.
this.Command i det här exemplet är egenskapen Kommando på ICommandSource. Om kommandot inte är null skickas kommandot till en RoutedCommand. Om det är en RoutedCommandExecute anropas metoden för att skicka CommandTarget och CommandParameter. Om kommandot inte är en RoutedCommandomvandlas det till en ICommand och Execute metoden kallas för att skicka 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
Kommentarer
Den faktiska logiken RoutedCommand som kör finns inte i Execute metoderna. Executegenererar PreviewExecuted händelserna och Executed som tunnel och bubblar genom elementträdet och letar efter ett objekt med .CommandBinding Om en CommandBinding för som RoutedCommand hittas anropas den anslutna ExecutedRoutedEventHandler till CommandBinding . Dessa hanterare tillhandahåller programmeringslogik RoutedCommandsom utför .
Händelserna PreviewExecuted och Executed aktiveras på CommandTarget. CommandTarget Om inte har angetts för ICommandSourcePreviewExecuted , aktiveras händelserna och Executed på elementet med tangentbordsfokus.