Value Changed Routed Event Arguments 1.0

Are you writing a custom routed event? Does that routed event signify a value changing? If so, consider ValueChangedRoutedEventArgs<T>. All you need to do is specify the type of the value which changed and access the OldValue and NewValue properties within the event handler. If you need this capability, be sure to look at the Generic Routed Event Handler, which will support you. Here's an example, which looks more complicated than it really is.

public static readonly SelectedIndexChanged = EventManager.RegisterEvent("SelectedIndexChanged", 
    RoutedEventStrategy.Bubble, typeof(RoutedEventHandler<ValueChangedRoutedEventArgs<int>>), typeof(MyClass));
...
private void MyClass_SelectedIndexChanged(object sender, ValueChangedRoutedEventArgs<int> args)
{
    if (args.OldValue == args.NewValue)
    {
        return;
    }
}

Last edited Jan 24, 2009 at 5:52 AM by flanakin, version 1

Comments

No comments yet.