Populating treeview from xml data with xmldataprovider



I have tried to do this task but i don't know what's the problem????



<Window x:Class="WpfApplication5.Window3"
xmlns="http://ift.tt/o66D3f"
xmlns:x="http://ift.tt/mPTqtT"

Title="Window3" Height="390" Width="700" Loaded="Window_Loaded">
<Window.Resources>
<XmlDataProvider x:Key="Shared"
XPath="/qtpRep:ObjectRepository"></XmlDataProvider>

<HierarchicalDataTemplate x:Key="keywords">
<TextBox Text="{Binding XPath=@Class}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="rootTemplate" ItemsSource="{Binding XPath=qtpRep:Objects/qtpRep:Object}" ItemTemplate="{StaticResource keywords}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="( " />
<TextBox Text="{Binding XPath=@Name}"/>
<TextBlock Text=")" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="root" ItemsSource="{Binding XPath=ChildObjects/qtpRep:Object}" ItemTemplate="{StaticResource keywords}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="( " />
<TextBox Text="{Binding XPath=@Name}"/>
<TextBlock Text=")" />
</StackPanel>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<TreeView Margin="0,0,0,148">
<TreeViewItem
ItemsSource="{Binding Source={StaticResource Shared}, XPath=qtpRep:Objects}" ItemTemplate="{StaticResource root}" Grid.ColumnSpan="2" />

</TreeView>
<Button Content="Button" Height="82" HorizontalAlignment="Left" Margin="166,266,0,0" Name="button1" VerticalAlignment="Top" Width="4" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="174,283,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
</Grid>


This is XAML code



<qtpRep:ObjectRepository xmlns:qtpRep="http://ift.tt/1AVjbNM">

<qtpRep:Objects>

<qtpRep:Object Class="Window" Name="Your PC information">
<qtpRep:ChildObjects>

<qtpRep:Object Class="WinObject" Name="OUTILBARREBOUTON">


.........


This is a portion of my XML file but it contains the essential structure (Objects contain object and object contains childobject and child object contain object)



public partial class Window3 : Window
{
XmlDataProvider Shared;

public Window3()
{
InitializeComponent();
}


private void Window_Loaded(object sender, RoutedEventArgs e)
{
Shared = FindResource("Shared") as XmlDataProvider;

}


private void button2_Click(object sender, RoutedEventArgs e)
{
var xmlDocument = new XmlDocument();

xmlDocument.Load("D:\\shared_repository.xml");

Shared.Document = xmlDocument;
}

No comments:

Post a Comment