ExecutedRoutedEventHandler Delegate

Definition

表示将处理 ExecutedPreviewExecuted 路由事件以及相关附加事件的方法。Represents the method that will handle the Executed and PreviewExecuted routed events, as well as related attached events.

public delegate void ExecutedRoutedEventHandler(System::Object ^ sender, ExecutedRoutedEventArgs ^ e);
public delegate void ExecutedRoutedEventHandler(object sender, ExecutedRoutedEventArgs e);
type ExecutedRoutedEventHandler = delegate of obj * ExecutedRoutedEventArgs -> unit
Public Delegate Sub ExecutedRoutedEventHandler(sender As Object, e As ExecutedRoutedEventArgs)

Parameters

sender
Object

事件处理程序附加到的对象。The object where the event handler is attached.

e
ExecutedRoutedEventArgs

事件数据。The event data.

Inheritance
ExecutedRoutedEventHandler

Examples

此示例创建一个 ExecutedRoutedEventHandler,该在执行命令时设置目标的视觉对象属性。This example creates an ExecutedRoutedEventHandler that sets a visual property on the target when the command is executed. 该示例还包括同一命令的 CanExecuteRoutedEventHandlerThe example also includes the CanExecuteRoutedEventHandler for the same command.

// ExecutedRoutedEventHandler for the custom color command.
private void ColorCmdExecuted(object sender, ExecutedRoutedEventArgs e)
{
    Panel target = e.Source as Panel;
    if (target != null)
    {
        if (target.Background == Brushes.AliceBlue)
        {
            target.Background = Brushes.LemonChiffon;
        }
        else
        {
            target.Background = Brushes.AliceBlue;
        }
    }
}

// CanExecuteRoutedEventHandler for the custom color command.
private void ColorCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    if (e.Source is Panel)
    {
        e.CanExecute = true;
    }
    else
    {
        e.CanExecute = false;
    }
}
' ExecutedRoutedEventHandler for the custom color command.
Private Sub ColorCmdExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    Dim target As Panel = TryCast(e.Source, Panel)
    If target IsNot Nothing Then
        If target.Background Is Brushes.AliceBlue Then
            target.Background = Brushes.LemonChiffon
        Else
            target.Background = Brushes.AliceBlue
        End If

    End If
End Sub

' CanExecuteRoutedEventHandler for the custom color command.
Private Sub ColorCmdCanExecute(ByVal sender As Object, ByVal e As CanExecuteRoutedEventArgs)
    If TypeOf e.Source Is Panel Then
        e.CanExecute = True
    Else
        e.CanExecute = False
    End If
End Sub

Remarks

此委托包含 RoutedCommand的实现逻辑。This delegate contains the implementation logic for a RoutedCommand. 通过从命令分离实现逻辑,可从不同的源和类型调用命令,并实现命令逻辑的集中。Separating the implementation logic from the command allows the command to be invoked from different sources and types, and enables the centralization of command logic.

此委托还用于 CommandManager.ExecutedCommandManager.PreviewExecuted,这是实现许多命令基础结构的 CommandManager 类上的附加事件。This delegate is also used for CommandManager.Executed and CommandManager.PreviewExecuted, which are attached events on the CommandManager class that implements much of the commanding infrastructure. 但大多数实际处理程序将处理来自特定 CommandBindingExecuted 事件,而不是在 CommandManager 级别工作。But most practical handlers will handle the Executed events from a particular CommandBinding, rather than work at the CommandManager level.

ExecutedRoutedEventArgs中,当你为通过执行的命令生成的路由事件编写事件处理程序时,通常会对以下属性感兴趣:Within ExecutedRoutedEventArgs, the following properties are generally of interest when you write an event handler for a routed event that results from an executed command:

  • Source 报告执行命令的目标。Source reports the target where the command was executed. 执行命令后,还可以将 Source 更常见的方式视为路由事件术语,作为引发路由事件的对象。Once the command is executed, you can also think of the Source more generally in routed event terms, as the object that raised a routed event.

  • Command 报告执行的命令。Command reports the command that executed. 如果使用命令绑定并且编写可能处理多个命令的处理程序,则此属性很有用。This property is useful if you use command bindings and if you write handlers that potentially handle multiple commands.

  • Parameter 报告执行命令传递的任何特定于命令的参数。Parameter reports any command-specific parameters that were passed by the executing command. 并非所有命令都使用或需要命令特定的参数。Not all commands use or expect command-specific parameters.

  • Handled 报告由执行命令产生的路由事件是否已由路由中的其他元素处理。Handled reports whether the routed event that resulted from the executed command was already handled by a different element along the route. 对于路由事件处理程序,建议在处理事件时,让处理程序执行有意义的工作,以将 Handled 设置为 trueFor routed event handlers, it is a recommended practice to have handlers that do meaningful work when handling the event to set Handled to true. 这会阻止事件的典型处理程序再次沿着路由再次处理事件。This prevents typical handlers for the event from handling the event again further along the route. 有关处理路由事件的详细信息,请参阅将路由事件标记为 "已处理" 和 "类处理"。For more information on handling routed events, see Marking Routed Events as Handled, and Class Handling.

此委托还表示 CommandManager.ExecutedCommandManager.PreviewExecutedEvent的处理程序,这些处理程序是实现许多命令基础结构的 CommandManager 类上的附加事件。This delegate also represents handlers for CommandManager.Executed and CommandManager.PreviewExecutedEvent, which are attached events on the CommandManager class that implements much of the commanding infrastructure. 但大多数实际处理程序将处理来自特定 CommandBindingExecuted 事件,而不是在 CommandManager 级别工作。But most practical handlers will handle the Executed events from a particular CommandBinding, rather than work at the CommandManager level.

有关命令的详细信息,请参阅命令概述For more information on commanding, see Commanding Overview.

Extension Methods

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

Applies to

See also