Yes, I need to use XPath
, but there s more to it.
My mistakes were:
You can t use a DataSet
directly but need to wrap it in a XmlDataDocument
Also my problem involved the namespaces. To surpress them you have to set DataSet.Namespace = String.Empty
prior to creating the XmlDataDocument
.
If you want to use Namespaces you have to create a XmlNamespaceMappingCollection
in XAML like this
<UserControl.Resources>
<XmlNamespaceMappingCollection x:Key="namespace">
<XmlNamespaceMapping Prefix="ds" Uri="http://tempuri.org/DataSet.xsd" />
</XmlNamespaceMappingCollection>
</UserControl.Resources>
In order to reference the namespace in the XPath. Simply adding it as xmlns won t work (as opposed to what I expected).
Then referencing a certain row worked like this:
<Label Content="{Binding XPath= //TableName[4] }" />
如果你使用名称空间,你需要参考<代码>。 XmlNamespaceManager
<Label Content="{Binding XPath= //ds:TableName[4] }" Binding.XmlNamespaceManager="{StaticResource namespace}" />
现在,虽然这种非常简单的XPath工作,但增加一项制约因素将导致完全使用CPU,我的方案不会继续:
<Label Content="{Binding XPath= //TableName[Process = 4] }" />
or
<Label Content="{Binding XPath= //ds:TableName[ds:Process = 4] }" Binding.XmlNamespaceManager="{StaticResource namespace}" />
EDIT
It seems like the binding must be in OneTime
Mode. Simply changing it to
<Label Content="{Binding Mode=OneTime, XPath= //TableName[Process = 4] }" />
使之发挥作用。 我也使用<代码>ContentTemplate,在模板中,约束力可以是TwoWay
,但XPath是首要的(例如/Prozess
)。