'DataTrigger XPath condition on tag
I have a XML file nodes.xml which I would like to show in TreeView
<?xml version="1.0" encoding="utf-8"?>
<nodes>
<node1 attr1="val1"/>
<node2 attr2="val2"/>
</nodes>
Every node should be shown, attr1 of node1 and attr2 of node2 I want to put in one element.
So I make a conditional TextBlock but don't know how to make condition like Binding = Tag Value = "node2"
<Window.Resources>
<XmlDataProvider x:Key="nodes" Source="nodes.xml" XPath="nodes/*"/>
</Window.Resources>
<Grid>
<TreeView ItemsSource="{Binding Source={StaticResource nodes}}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding}">
<TextBlock>
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Text" Value="{Binding XPath=@attr1}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding XPath=???}" Value="node2">
<Setter Property="Text" Value="{Binding XPath=@attr2}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
I'm almost sure that replace ??? with something like "Tag" will be enough because this condition with attribute value for example works fine. name() doesn't work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
