views:

171

answers:

1

I defined a custom routed event with the following constructs (names changed):

public class MyRoutedEventArgs : RoutedEventArgs {...}

public delegate void MyRoutedEventHandler(Object sender, MyRoutedEventArgs args);

public static readonly RoutedEvent MyEvent;

MyClass.MyEvent = EventManager.RegisterRoutedEvent("MyEvent", RoutingStrategy.Tunnel, typeof(MyRoutedEventHandler), typeof(MyClass));

Next, I'm creating a CLR event wrapper:

public event MyRoutedEventHandler MyEvent { add { AddHandler(MyEvent, value); } remove { RemoveHandler(MyEvent, value); } }

The problem is when I define it as shown above, XAML intellisense doesn't work for autogenerating the handler method body. What I noticed is that if you change your CLR event wrapper to use generic RoutedEventHandler type, everything works! However in this case, the auto-generated method gets a generic RoutedEventArgs (well, correctly corresponding to RoutedEventHandler), which forces me to manually rewrite it as MyRoutedEventArgs.

A: 

I think this is currently a limitation you have to live with. But all you have to do is, once the eventhandler for the generic type was autogenerated, change the signature of the generated method to use MyRoutedEventArgs instead of RoutedEventArgs. Allthough still ugly (we shouldn't be forced to do this) I would think it is not such a big problem.

Anyone tried it with VS 2010 ?

bitbonk
Haven't tried on VS 2010. The strange thing is that for framework's own events with non-generic handlers (such as MouseDown, etc.) it works perectly fine.