开发者

Keeping the TreeView and the Nodes separate

I have a problem concerning good application design that has been keeping me up for days now. One can describe it as:

  • I have a tree structure made up of Nodes holding references to their children.
  • I would now like to display that structure in a TreeView (I am the one开发者_运维百科 who will implement the TreeView).
  • I don't want the Nodes to 'know' that there is a TreeView, enabling me to keep those two components separate.

So where do I store the information whether an node is expanded or not (this information is not part of the Node itself).

Any idea on how to implement this in a clean way?

Thanks,

Konne


Create a TreeViewModal class that binds the view and the actual modal. Apparently this is known as Model/View/ViewModel pattern. Here is an example for the TreeView. Both the links has code in C# but it is easy to port to any language.


If each node has a unique hashable key you could add a hash table to TreeView to contain the keys of the expanded nodes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜