wpf - 在wpf treeview中,如何用以前的扩展值重绘节点(使用MVVM)

标签 wpf mvvm treeview refresh gridviewcolumn

我正在开发一个具有严格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/

相关文章:

c# - Master/Detail MVVM 中的 Wpf Combobox

c# - 双击 TreeNode 复选框上的行为

c# - 为什么我的 TreeView 不更新?

c# - 如何将值从富文本框传递到另一个富文本框

wpf - 如何在WPF中的ListBox中编写 "Selection Changing"事件?

c# - 如何更新现有行的值而不是添加新行

javascript - 性能 : listen to all form elements changes to sync all dynamic attributes with new data

c# - 在更改的回调中设置 DependencyProperty 值

delphi - delphi中如何从数据库中检索数据并显示在Ttreeview中

c# - 如何合并集合中的两个源并在组合框中正确显示它们?