RoutedEventArgs.RoutedEvent 属性

定义

获取或设置与此 RoutedEventArgs 实例关联的 RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance.

public:
 property System::Windows::RoutedEvent ^ RoutedEvent { System::Windows::RoutedEvent ^ get(); void set(System::Windows::RoutedEvent ^ value); };
public System.Windows.RoutedEvent RoutedEvent { get; set; }
member this.RoutedEvent : System.Windows.RoutedEvent with get, set
Public Property RoutedEvent As RoutedEvent

属性值

已调用的事件的标识符。The identifier for the event that has been invoked.

异常

在路由事件时试图更改 RoutedEvent 值。Attempted to change the RoutedEvent value while the event is being routed.

示例

下面的示例使用初始构造函数创建新的路由事件数据,然后将 RoutedEvent 属性设置为后续操作。The following example creates new routed event data with an initial constructor and then sets the RoutedEvent property as a subsequent operation. 在引发路由事件之前,必须设置 RoutedEventYou must have RoutedEvent set prior to raising the routed event.

protected virtual void OnSelectedColorChanged(Color oldColor, Color newColor)
{

    RoutedPropertyChangedEventArgs<Color> newEventArgs =
        new RoutedPropertyChangedEventArgs<Color>(oldColor, newColor);
    newEventArgs.RoutedEvent = ColorPicker.SelectedColorChangedEvent;
    RaiseEvent(newEventArgs);
}
Protected Overridable Sub OnSelectedColorChanged(ByVal oldColor As Color, ByVal newColor As Color)

    Dim newEventArgs As New RoutedPropertyChangedEventArgs(Of Color)(oldColor, newColor)
    newEventArgs.RoutedEvent = ColorPicker.SelectedColorChangedEvent
    MyBase.RaiseEvent(newEventArgs)
End Sub

注解

不能对已路由的 RoutedEventArgs (例如,如果通过处理程序获取了参数)设置此值。You cannot set this value on a RoutedEventArgs that has already been routed (for instance, if you obtained the arguments through a handler). 如果尝试这样做,将生成异常。Attempting to do so will generate an exception. 只能在尚未用于生成事件调用的实例上设置此方法。You can only set it on an instance that has not yet been used to generate an invocation of the event.

不能随时 null RoutedEvent 的值。The value of RoutedEvent cannot be null at any time.

适用于