开发者

Is it possible to setup Event Bubbling and Event Tunelling for standard class not just for XAML classes?

In a WPF or Silverlight Is it possible to have a custom hierarchy of standard classes not associated with GUI classes and setup vent Bubbling and Event Tunelling for this hierarchy ? How ?

when looking at events I don't see anything开发者_运维知识库 really related to bubbling or tunneling http://msdn.microsoft.com/en-us/library/system.windows.uielement_events.aspx


Routed events require that the object inherits from UIElement class, which pretty much destines it to be a GUI control.

All such classes can be instantiated from code behind (C#/VB/...) though. XAML just provides a convenient way to declaratively define objects, it doesn't do anything that can't be done from code behind.


It's not possible using the .net framework, unless you create something similar to the functionality the EventManager class provides you. Suppose you started implementing. Then you would have to traverse up & down a graph of objects (if your class hierarchy isn't a tree). For this you would somehow need to identify which objects are actually are part of the tree and which aren't.
Suppose you have the following:

class A
{
   public B b;
}

class B
{

}


B b1 = new B();
A a1 = new A() { b = b1 };
A a2 = new A() { b = b1 };

Suppose b1 raises a bubbling event. To which parent should it bubble? a1 or a2? Bubbling & tunneling in WPF & Silverlight work because you have UIElements which are in a Tree, not in a graph like in the scenario above. But arbitrary class hierachies are graphs not trees. So if you would start implementing something similar it would only work for a tree class similar to the following.

class Node 
{
   Node parent;
   //other members
}

Then you would know how to always bubble using the "parent" property.

But, before you start implementing your EventManager, I would suggest you take another look at what RoutedEvents are and what are the scenarios to use them: http://msdn.microsoft.com/en-us/library/ms742806.aspx Also maybe you could provide us with the scenarios where routed events would be useful for a standard (non-ui) class hierachy (tree) to see if we can find an alternative to RoutedEvents.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜