多层“全部展开”对于扩展器?
我正在编写一个 MVVM 配置接口,并且我正在尝试实现一个适用于所有视图的展开/折叠所有功能。
顶级 ViewModel 是其他 ViewModel 的同类集合,它绑定到视图中的 ItemsControl。这些子 ViewModel 中的每一个都有许多依赖的 ViewModel,每个 ViewModel 都绑定到 View 中的 ContentControl。从视觉上看,这采用一组扩展器(例如 3 个)的形式,每个扩展器内部隐藏有 4-6 个扩展器。
我尝试过自上而下的搜索方法。由于顶级扩展器已折叠,因此它们的子扩展器在第一次显示之前甚至不存在(Caliburn.Micro 在第一次要求它们时为它们执行查看位置),并且“全部展开”行动仅扩展第一级。
逻辑树也没有任何帮助。顶级 ItemsControl 的 Items
属性实际上包含我的 ViewModel 类型的对象,因此我无法在它们内部查找扩展器。
我曾考虑过在 ViewModel 级别进行管理,但向所有虚拟机添加 IsExpanded 属性并使用某些全局管理器进行设置似乎很混乱。虚拟机没有其他原因知道哪些扩展器已扩展。
处理这个问题的最佳方法是什么?我可以使用一些附加属性绑定技巧吗?
I'm writing an MVVM configuration interface, and I'm trying to implement an expand/collapse all function that applies to all the views.
The top-level ViewModel is a homogeneous collection of other ViewModels, which is bound to an ItemsControl in the view. Each of these child ViewModels has a number of dependent ViewModels, each of which is bound to a ContentControl in the View. Visually, this takes the form a a set of expanders (say, 3 of them), each of which has 4-6 expanders hidden inside.
I've tried top-down search methods. Since the top-level expanders are collapsed, their child expanders don't even exist until they are shown for the first time (Caliburn.Micro is doing view location for them when they're first asked for), and the "expand all" action only expands the first level.
The logical tree isn't any help either. The top-level ItemsControl's Items
property actually contains objects of my ViewModel type, so I can't look inside them for expanders.
I've thought of managing this at the ViewModel level, but adding an IsExpanded
property to all of the VMs and setting it using some global manager seems messy. There's no other reason for the VM to know which expanders are expanded.
What's the best way of handling this? Is there some attached-property binding trick I could pull?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 ViewModel 应该有一个可以扩展自身并在其子级中调用相同函数的函数。
现在您只需连接“全部展开”操作即可使用适当的参数调用 SetSelfAndChildrenExpandedState() 。
这可能对你有用......考虑一下。
Your ViewModel should have a function that expands itself and calls the same function in its children.
Now you just have to hook up your "expand all" action to call SetSelfAndChildrenExpandedState() with the appropriate parameter.
That might work for you...give it a thought.