I am working on a genealogy application and I plan to store references to each family member in an XML document. I would like to read this document and display it as a treeview in my application and then use it to display a family member elsewhere in the application. What I need to do is find a specific value in the node tree (each member will have a unique value). How would I find this value? Could you please give me a hand here, I am quite new to node editing. TY.
BTW, below is my XAML code:
<HierarchicalDataTemplate x:Key="NodeTemplate">
<HierarchicalDataTemplate.ItemsSource>
<Binding XPath="child::*" />
</HierarchicalDataTemplate.ItemsSource>
<TextBlock Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
<XmlDataProvider x:Key="xmlDataProvider"></XmlDataProvider>
</Window.Resources>
<Grid>
<TreeView Margin="0,24,0,143"
Name="treeView1"
Background="AliceBlue"
ItemsSource="{Binding Source={StaticResource xmlDataProvider}, XPath=*}"
ItemTemplate= "{StaticResource NodeTemplate}"/>
I’ve assumed that the unique value is the
idattribute. So the code will look so:If your xml file has a different attribute as an identifier, change this line accordingly:
item.HasAttribute("id") && item.GetAttribute("id").The final result will be the
XmlElementobject. But it isn’t easy to retrieve the container because of the algorithm of generation of treeview items. Anyway, if you have a specific question – I can help to build a correct architecture.