我正在开发一个具有严格MVVM模式的wpf桌面应用程序。
当前我的应用程序正在执行以下操作:
- Showing a Treeview with HierarchicalDataTemplate.
- User can expand or collapse Nodes.
- User can add add new Nodes(Drag n Drop + double click).
- Everytime a new Node is added Model is updated and Treeview is recreated based on Model.
- Because Treeview is recreated, all nodes are shown as expanded after adding nodes.
我想显示节点及其之前的扩展状态。有没有办法使用 MVVM 来做到这一点?到目前为止我的想法是
- Model should not contain any data related to how to draw UI ??
- VM should just get data from Model and put it in UI(and pass date from UI to Model) ??
谢谢你的想法。我可能离铁路还很远。但只是想从你们那里得到一些智慧。
谢谢
派贾
最佳答案
如果您还没有阅读过 Josh Smith 的这篇精彩文章:Simplifying the WPF TreeView by Using the ViewModel Pattern
基本上,他建议在虚拟机中包含一个名为 IsExpanded
的属性,并将 TreeView
正确绑定(bind)到它,以便展开/折叠状态完全由程序员。
关于wpf - 在wpf treeview中,如何用以前的扩展值重绘节点(使用MVVM),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2196838/