RoutedEventArgs.RoutedEvent Property

Definition

Gets or sets the RoutedEvent associated with this RoutedEventArgs instance.

C#
public System.Windows.RoutedEvent RoutedEvent { get; set; }

Property Value

The identifier for the event that has been invoked.

Exceptions

Attempted to change the RoutedEvent value while the event is being routed.

Examples

The following example creates new routed event data with an initial constructor and then sets the RoutedEvent property as a subsequent operation. You must have RoutedEvent set prior to raising the routed event.

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

    RoutedPropertyChangedEventArgs<Color> newEventArgs =
        new RoutedPropertyChangedEventArgs<Color>(oldColor, newColor);
    newEventArgs.RoutedEvent = ColorPicker.SelectedColorChangedEvent;
    RaiseEvent(newEventArgs);
}

Remarks

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.

The value of RoutedEvent cannot be null at any time.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9