This is XML file
<Root>
<RootNode name="CurrentDbName" value="DeltaTest Backup" DesiPath="E:\BuildBackups">
<ChildNode name="Application" value="App">
<LeafNode name="Source" value="Source" SourcePath="E:\Alertv2" />
<LeafNode name="Publish" value="Publish" SourcePath="C:\Alert_Source" />
</ChildNode>
<ChildNode name="Database" value="DB">
<LeafNode name="Dev" value="Dev" SourcePath="C:\Kiran3" />
<LeafNode name="Build" value="Build" SourcePath="C:\Kiran4" />
</ChildNode>
</RootNode> </Root>
From this, I want to create a treeview in WPF and looks like
-Root
--DeltaTestBaclup
---App
----Source
----Publish
---Db
----Dev
----Build
So please help me to create this treeview.
This is the most generic version for every xml structure. For example :
Will produce this :
Welcome to stackoverflow, if you could post some sample xml - it would help to visualise what your working towards. I think you need to use 1 or more
HierarchicalDataTemplate
.Assuming an xml file called data.xml:
You could use xaml something similar to:
I know this question was asked a few months ago but I don't think it was answered accurately as I ran into the same problem and none of these suggestions helped me solve it.
Here's a link that explains how to populate a treeview from an .xml using winforms:
http://www.codeproject.com/Articles/12606/Loading-and-Saving-XML-to-and-from-a-TreeView-Cont
I managed to adapt it to wpf so to populate a TreeView using the info in an .xml:
Here is a way to do it programmatically. This is based on this website's solution
That code behind will build the tree to your spec. This is the XAML
You can read about that here, an example from that site:
That would result in this
alt text http://www.c-sharpcorner.com/UploadFile/mahesh/WPFTreeView08202008231544PM/Images/WPFTreeViewImg1.jpg
So in your case you need to add some more TreeViewItems and nest them up a bit, play with the above code to get the result you want!