展开 WPF Expander 以将包含的元素带入视图
我有一个包含 n 个元素的扩展器(可能还有也包含元素的其他扩展器)。
现在我想以编程方式将包含的元素带入视图 - 就像 ScrollViewers 的 BringIntoView() 一样。当前隐藏该元素的所有扩展器都应该展开。
我当前的想法是对 Expander 进行子类化,并使其对从包含的元素中冒出的事件做出反应。但 WPF 中可能有更简单的方法,对吧?
I have an expander that has n contained elements (possibly other Expanders that also contain elements).
Now I want to programmatically bring a contained element into view - like with BringIntoView() for ScrollViewers. All Expanders that currently hide the element should expand.
My current idea is to subclass the Expander and make it react to an event that bubbles up from the contained element. But there may be a much easier way in WPF, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个附加属性来执行此操作,而不是对现有 Expander 类进行子类化。该 AP 的类型为 bool,当在扩展器上设置为 True 时,会注册 Expanded 事件。在事件处理程序中,您可以沿着逻辑树向上走以获取父级 Expander,toogle 是 IsExpanded 属性。
You can create an attached property to do that instead of subclassing the existing Expander class. This AP would be of type bool, and when sets to True on an expander register for the Expanded event. In the event handler, you can walk up the logical tree to grab the parent Expander and toogle is IsExpanded property.