I'd like t开发者_运维百科o bind to the element name of a node in my XmlDataProvider
. I can't seem to get local-name() to work within my XPath expression. Does XAML support local-name()?
<TextBlock Text="{Binding XPath=local-name()}" />
I have been trying to do exactly the same thing and am pretty sure it is not supported in a single step.
The Binding.XPath help says The XmlNode::SelectNodes method handles the XPath expressions from the XPath property. XPath functions are not supported.
However
You can work around it using a bit of a hack - you need a container around the element to provide a DataContext which is the result of your XPath and then you can query the LocalName property of that context object using Path, such as in my working example:
<StackPanel Grid.Row="20" Grid.Column="1"
DataContext="{Binding XPath=r:Result/r:LIC1}">
<TextBlock Text="{Binding Path=LocalName}" />
</StackPanel>
which I'd originally been trying to achieve with:
<TextBlock Grid.Row="20" Grid.Column="1"
Text="{Binding XPath=r:Result/r:LIC1/local-name\(\)}" />
精彩评论