XAML 对 XPath 中 local-name() 的支持 [英] XAML support for local-name() in XPath
问题描述
我想绑定到我的 XmlDataProvider
中节点的元素名称.我似乎无法让 local-name() 在我的 XPath 表达式中工作.XAML 是否支持 local-name()?
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()}" />
推荐答案
我一直在尝试做完全相同的事情,但我很确定它在一个步骤中不受支持.
I have been trying to do exactly the same thing and am pretty sure it is not supported in a single step.
Binding.XPath 帮助说XmlNode::SelectNodes 方法处理来自 XPath 属性的 XPath 表达式.不支持 XPath 函数.
The Binding.XPath help says The XmlNode::SelectNodes method handles the XPath expressions from the XPath property. XPath functions are not supported.
不过
您可以使用一些技巧来解决它 - 您需要一个围绕元素的容器来提供一个 DataContext,它是您的 XPath 的结果,然后您可以使用 Path 查询该上下文对象的 LocalName 属性,例如在我的工作示例中:
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\(\)}" />
这篇关于XAML 对 XPath 中 local-name() 的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!