tags:

views:

184

answers:

1

I'd like to 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()}" />
A: 

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\(\)}" /> 
Andy Dent
The quote you provided from the documentation seems to be key: "XPath functions are not supported." I wonder why a limitation like that is not in bigger letters?
emddudley