WPF - 将TreeView转换为XML [英] WPF - Convert TreeView to XML
本文介绍了WPF - 将TreeView转换为XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i希望将WPF TreeView转换为XML。
我的treeView没有绑定因为它能够加载其他treeView的。
使用WFA你可以在WPF上使用节点吗?
坦克你回答
M
Hi,
i want to convert a WPF TreeView to XML.
I have no binding on my treeView because it will be able to load other treeView's.
With WFA you can use "nodes" but on WPF?
Tank you for answering
M
推荐答案
您可以遍历所有内容TreeView
:
http://msdn.microsoft.com /en-us/library/system.windows.controls.itemscontrol.items.aspx [ ^ ](System.Windows.Controls.ItemsControl.Items
的属性和因此System.Windows.Controls.TreeView
),
HTTP://msdn.micros oft.com/en-us/library/system.windows.controls.treeviewitem%28v=vs.110%29.aspx [ ^ ](代表单个节点,也有Items
property),
另见 http://msdn.microsoft.com/en-us/library/system.windows.controls.treeview.aspx [ ^ ]。
要编写XML,.NET FCL提供了不同的功能。这是我对他们的简短概述:
You have everything to traverseTreeView
:
http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.items.aspx[^] (property ofSystem.Windows.Controls.ItemsControl.Items
and henceSystem.Windows.Controls.TreeView
),
http://msdn.microsoft.com/en-us/library/system.windows.controls.treeviewitem%28v=vs.110%29.aspx[^] (represents a single node, also hasItems
property),
see also http://msdn.microsoft.com/en-us/library/system.windows.controls.treeview.aspx[^].
To write XML, .NET FCL provides different facilities. This is my short overview of them:
- 使用
System.Xml.XmlDocument
class 。它实现了DOM接口;如果文档的大小不是太大,这种方式是最简单和最好的。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ]。 - 使用类
System.Xml.XmlTextWriter
和System.Xml.XmlTextReader
;这是最快的阅读方式,特别是你需要跳过一些数据。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx [ ^ ], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ ^ ]。 - 使用类
系统.Xml.Linq.XDocument
;这是类似于XmlDocument
的最合适的方式,支持LINQ to XML Programming。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ],http://msdn.microsoft.com/en-us/library/bb387063.aspx [ ^ ]。
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the classes
System.Xml.XmlTextWriter
andSystem.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that ofXmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
这篇关于WPF - 将TreeView转换为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文