When I try to get the eventinfo of a WPF ‘rectangle’, if the routedEvent is a native event to the object (e.g. ‘MouseDown’) it works (assignments are for example only).
DependencyObject d = rectangle;
string routedEvent = "MouseDown";
EventInfo eventInfo = d.GetType().GetEvent(routedEvent,
BindingFlags.Public | BindingFlags.Instance);
But when I want to get the EventInfo for an attached event (I think I am using that term correctly) on the rectangle like:
string routedEvent = "Microsoft.Surface.Presentation.Contacts.ContactDownEvent";
GetEvent() returns null
Any idea on how to get the eventinfo for an attached event.
Thanks
Dan
You may want to use the more specific
EventManager.GetRoutedEventsForOwnermethod.I believe the MSDN docs are incorrect when they say:
Here’s proof:
Therefore, you may need to crawl the type hierarchy yourself, or if it’s a one-off just pass in
typeof(FrameworkElement)instead ortypeof(Rectangle).