I’m trying to bind to some XML data from my WPF application. I’ve set up the data context so that the XmlElement I’m trying to bind to ends up looking like this:
<Item name="Potion" classes="Healing Item" value="200">
<Classes>
<Class value="HealingItem" />
</Classes>
<Description value="A low quality potion, it restores a small amount of health" />
<Components>
<HealingComponent>
<BattleHealingComponent>
<HPHealingComponent value="500" type="Absolute"/>
</BattleHealingComponent>
</HealingComponent>
</Components>
</Item>
Now here’s the problem. I can’t figure out an XPath query I can bind with that will return only the Component Subnodes.
I know it’ll go something like this:
ItemsSource="{Binding XPath=Components/*/????}"
I’m stuck on what to use for ????
The result of this query should display “HealingComponent” I’ve tried playing around with various different parameters on an online XPath visualizer, but I can’t figure this one out. I ready about name(), but I can’t seem to get that to work.
Any help would be appreciated
In addition to the
ItemsSourceyou probably need anItemTemplate, this should work:If you do not intend to do anything fancy you can also use the
DisplayMemberPath, though in this case the binding ensures thatNameis not interpreted as an XPath, you may not have that kind of control withDisplayMemberPath.