I'm attempting to bind an XML document to wpf, via datacontext, and am having trouble figuring out how to do property binding
Assuming an xml file like:
<Vehicles>
<Vehicle Name="Test" Vehicle_Id="1"/>
</Vehicles>
How do I achieve what I'm attempting below,
attempt 1:
<TextBlock DataContext="{Binding XPath=/Vehicles/Vehicle[@Vehicle_Id='1']}" Text="{Binding XPath=@Name}"/>
attempt 2:
<TextBlock T开发者_如何学Cext="{Binding XPath=/Vehicles/Vehicle[@Vehicle_Id='1']/@Name}"/>
e.g. is it possible to use filter clauses on the xpath for datacontext
As I'm seriously new to WPF, I accept that I may be completely missing the point of DataContext in this context.
Thanks in advance!
You should try setting up a XmlDataProvider. Check out Bea Stollnitz's blog for examples of XML WPF XAML only binding methods.
精彩评论