我想使用TypeConverter将任何XML文档绑定到WPF TreeView.
我最初的解决方案是使用递归,但是当文档很大时,UI被严重束缚.
以下链接讨论TypeConverter,但针对特定节点/元素组合:http: //social.msdn.microsoft.com/Forums/en-US/wpf/thread/edd843b7-b378-4c2d-926f-c053dbd7b340
如果不知道XML文档是什么样的呢?由于这仅用于显示目的,我此时并不关心功能,我只想将XML绑定到TreeView.
我正在尝试使用WPF为表示层重写我的ForestPad应用程序.在WinForms中,我以编程方式填充每个节点,但如果可能的话,我想利用WPF的数据绑定功能.
一般来说,将WPF TreeView双向数据绑定到Xml文档的最佳方法是什么?
一般的解决方案很好,但作为参考,我试图绑定的Xml文档的结构如下所示:
<?xml version="1.0" encoding="utf-8"?>
<forestPad
guid="6c9325de-dfbe-4878-9d91-1a9f1a7696b0"
created="5/14/2004 1:05:10 AM"
updated="5/14/2004 1:07:41 AM">
<forest
name="A forest node"
guid="b441a196-7468-47c8-a010-7ff83429a37b"
created="01/01/2003 1:00:00 AM"
updated="5/14/2004 1:06:15 AM">
<data>
<![CDATA[A forest node
This is the text of the forest node.]]>
</data>
<tree
name="A tree node"
guid="768eae66-e9df-4999-b950-01fa9be1a5cf"
created="5/14/2004 1:05:38 AM"
updated="5/14/2004 1:06:11 AM">
<data>
<![CDATA[A tree node
This is the text of the tree node.]]>
</data>
<branch
name="A branch node"
guid="be4b0993-d4e4-4249-8aa5-fa9c940ae2be"
created="5/14/2004 1:06:00 AM"
updated="5/14/2004 1:06:24 AM">
<data>
<![CDATA[A branch node …Run Code Online (Sandbox Code Playgroud)