是否可以为标准类设置事件冒泡和事件调整,而不仅仅是 XAML 类?
在 WPF 或 Silverlight 中,是否可以拥有与 GUI 类不关联的标准类的自定义层次结构,并为该层次结构设置通风口冒泡和事件调节?如何 ?
在查看事件时,我没有看到任何与冒泡或隧道真正相关的内容 http://msdn.microsoft.com/en-us/library /system.windows.uielement_events.aspx
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
路由事件要求对象继承 UIElement 类,这几乎注定了它是一个 GUI 控件。
不过,所有此类都可以从代码隐藏(C#/VB/...)中实例化。 XAML 只是提供了一种以声明方式定义对象的便捷方法,它不会执行任何无法通过代码隐藏完成的操作。
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.
除非您创建类似于 EventManager 类为您提供的功能的东西,否则不可能使用 .net 框架。
假设你开始实施。然后你就必须向上遍历&沿着对象图向下(如果您的类层次结构不是树)。为此,您需要以某种方式确定哪些对象实际上是树的一部分,哪些不是。
假设您有以下情况:
假设 b1 引发冒泡事件。应该向哪位家长冒泡? a1还是a2?
冒泡& WPF 中的隧道Silverlight 之所以能够工作,是因为您的 UIElement 位于树中,而不是像上面的场景那样位于图表中。但任意的类层次结构都是图而不是树。
因此,如果您开始实现类似的东西,它只适用于类似于以下内容的树类。
然后你就会知道如何始终使用“parent”属性来冒泡。
但是,在开始实现 EventManager 之前,我建议您再看一下 RoutedEvents 是什么以及使用它们的场景是什么:http://msdn.microsoft.com/en-us/library/ms742806.aspx
另外,也许您可以向我们提供路由事件对于标准(非 ui)类层次结构(树)有用的场景,看看我们是否可以找到 RoutedEvents 的替代方案。
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:
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.
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.