2017-02-22 131 views
0

我有一個看起來像這樣的XML文件:在我的XAMLXML數據綁定

<Month name="Jan"> 
    <Comment source="Controller"> 
    <refs> 
     <ref account="1" content="1. Zeile"/> 
     <ref account="2" content="2. Zeile"/> 
     <ref account="3" content="3. Zeile"/> 
    </refs> 
    </Comment> 
    <Comment source="NatCo"> 
    <refs> 
     <ref account="1" content="4. Zeile"/> 
     <ref account="2" content="5. Zeile"/> 
     <ref account="3" content="6. Zeile"/> 
    </refs>  
    </Comment> 
</Month> 

和兩個列表框。第一個列表框應該顯示來自評論源控制器的評論。第二個應該顯示國家公司的意見。我如何根據source屬性指定數據綁定?

目前我的數據綁定看起來是這樣的:

ListBox Name="lstNaCo" ItemsSource="{Binding Path=Element[Comment].Element[refs].Elements[ref]}" 

是否有可能交出徵求意見元件的額外參數?對於這樣例子

Path=Element[[email protected]='Controller'].Element[refs].Elements[ref] 

回答

0

您可以使用XPath做到這一點很容易

<ListBox> 
    <ListBox.ItemsSource> 
      <Binding XPath="//Comment[@source='Controller']"/> 
    </ListBox.ItemsSource> 
</ListBox> 

你仍然需要設置源,你可能需要圍繞逃脫引號「控制器」。這裏有一些資源上手How to use XPathXPath syntax