Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF C#4.0
How to Create a WPF application to visualize a arbitrary XML document in a treeview and edit the treeview items
Posted 21-Sep-12 2:16am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1


xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="How to load XML into a TreeView control"
Height="400"
Width="550">

<!-- This HierarchicalDataTemplate will visualize all XML-nodes -->














<!-- This will contain the initial XML-data as well as any other file the user may pick at runtime. -->
<xmldataprovider x:key="xmlDP" xpath="*">




<title>XML in Action</title>
XML Web Technology


<title>Programming Microsoft Windows With C#</title>
C# Programming using the .NET Framework


<title>Inside C#</title>
C# Language Programming


<title>Introducing Microsoft .NET</title>
Overview of .NET Technology


<title>Microsoft C# Language Specifications</title>
The C# language definition




<title>Classical Collection</title>
Classical Music


<title>Jazz Collection</title>
Jazz Music




</xmldataprovider>
<!-- The following two styles allow for easy expanding/collapsing of all nodes. -->
<style x:key="TV_AllExpanded" targettype="{x:Type TreeView}">
<style.resources>
<style targettype="TreeViewItem">

</style>
</style.resources>
</style>
<style x:key="TV_AllCollapsed" targettype="{x:Type TreeView}">
<style.resources>
<style targettype="TreeViewItem">

</style>
</style.resources>
</style>







<button x:name="cmdLoadXml">
Content="Pick the XML document to be shown ..."
Margin="5"
Click="cmdLoadXml_Click"
ToolTip="Click here to pick an XML-document to be loaded."
/>

Background="LightYellow"
ItemTemplate= "{StaticResource NodeTemplate}"
ItemsSource="{Binding Source={StaticResource xmlDP}}"
Margin="5"
Grid.Row="1"
/>








<label content="Root-Node:">
Margin="5"/>

Margin="0,5"
Width="150"
Grid.Column="1"/>

Margin="5,0"
Grid.Column="2">
<button x:name="cmdChangeDisplayRootNode">
Click="cmdChangeDisplayRootNode_Click"
Margin="3"
Padding="3"
ToolTip="Click here to use the path specified in the TB to the left as the root display node."
Content="_Go"/>
<button x:name="cmdReset">
Click="cmdReset_Click"
Margin="3"
Padding="3"
ToolTip="Click here to reset the root display node (show all)."
Content="_Reset"/>
</button></button>


Margin="5,0"
Grid.Column="4">
<button x:name="cmdExpandAll">
Content="Expand all"
Margin="3"
Padding="3"
ToolTip="Click here to expand all TreeView nodes"
Click="cmdExpandAll_Click"/>
<button x:name="cmdCollapse">
Content="Collapse all"
Margin="3"
Padding="3"
ToolTip="Click here to collapse the TreeView"
Click="cmdCollapse_Click"/>
</button></button>

</label>

</button>

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,205
1 DamithSL 5,114
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,747
4 Kornfeld Eliyahu Peter 4,474


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100