是的,我需要使用XPath
,但有更多的東西。
我的錯誤是:
不能直接使用DataSet
但需要將其包裝在一個XmlDataDocument
也是我的問題涉及到的命名空間。爲了抑制它們,你必須在創建XmlDataDocument
之前設置DataSet.Namespace = String.Empty
。
如果你想使用命名空間,你必須這樣
<UserControl.Resources>
<XmlNamespaceMappingCollection x:Key="namespace">
<XmlNamespaceMapping Prefix="ds" Uri="http://tempuri.org/DataSet.xsd" />
</XmlNamespaceMappingCollection>
</UserControl.Resources>
XAML創建一個XmlNamespaceMappingCollection
爲了引用命名空間中的XPath。簡單地將它添加爲xmlns將不起作用(與我預期的相反)。
然後引用某行的工作是這樣的:
<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}" />
編輯 看起來綁定必須在OneTime
模式下。只需將其更改爲
<Label Content="{Binding Mode=OneTime, XPath='//TableName[Process = 4]'}" />
使其工作。我也使用ContentTemplate
,在模板中綁定可能是TwoWay
,但XPath是原始的(例如./Prozess
),也許這就是原因。
好的,它停止崩潰,如果我設置'模式'爲'OneTime', 雖然這不是我所需要的... – Mene 2010-01-07 17:40:38