Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML support for local-name() in XPath

Tags:

xaml

xpath

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()}" />
like image 210
sourcenouveau Avatar asked Nov 14 '22 14:11

sourcenouveau


1 Answers

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\(\)}" /> 
like image 51
Andy Dent Avatar answered Jan 01 '23 10:01

Andy Dent