WPF Reflections

Dec 3 2007   11:40AM GMT

Attached events



Posted by: Mark Shurmer
WPF

Firstly, what are they?

I say they are custom events that you can place into the tree in WPF to add extra functionality without subclassing controls.

The pure MSDN definition is:
“An attached event allows you to attach a handler for a particular event to some child element rather than to the parent that actually defines the event, even though neither the object potentially raising the event nor the destination handling instance define or otherwise ‘own’ that event in their namespace.”

However, you do have to read that quite a few times!
So I’ve broken it down into a few key elements:

  1. It is a normal WPF routed event
  2. They are custom events that mean you don’t have to subclass existing classes
  3. It is not a language event (with += & -= handlers in c#), you use AddHandler and RemoveHandler instead
  4. You can put them into attributes like standard system events

Hope that’s clear :-)

Comment on this Post


You must be logged-in to post a comment. Log-in/Register