2

我有一个xml这样的文件:

<Organizations xmlns="">
    <Organization  Title ="dfs" Score="70">
        <Layer  Title ="lar"></Layer>
    </Organization>
    <Organization  Title ="srwrg" Score="70">
        <Layer  Title ="asdf"></Layer>
        <Layer  Title ="lfdkj"></Layer>
    </Organization>
</Organizations>

我在我的 WPF 项目中使用这个文件:(这里是一个资源)

<XmlDataProvider x:Key="myData" Source="Data\farsDataOrganization.xml" XPath="//Organizations/Organization"/>

<CollectionViewSource x:Key="MyCVS" >
        <CollectionViewSource.Source>
            <Binding Source="{StaticResource myData}"/>
        </CollectionViewSource.Source>
        <CollectionViewSource.SortDescriptions>
            <scm:SortDescription PropertyName="@Title" Direction="Ascending"/>
        </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>

我知道如何根据组织Title或图层制作过滤器Title

 XmlDataProvider p = (XmlDataProvider)this.FindResource("myData");
 p.XPath = string.Format("//Organizations/Organization[Layer[contains(@Title,\"{0}\")]]", this.layerNameFilter.Text);

我想根据组织Title和图层过滤这些数据Title。有什么建议吗?如何更改我的XPath字符串以便我获得基于它们的过滤器?

编辑

我在 a 上显示这些数据TreeView

 <TreeView Grid.Row="1" ItemsSource="{Binding Source={StaticResource MyCVS}}">
     <TreeView.Resources>
         <HierarchicalDataTemplate DataType="Organization" ItemsSource="{Binding XPath=Layer}">
             <StackPanel Orientation="Vertical" Width="340" Margin="0,0,0,5">
                 <Label Content="{Binding XPath=@Title}" FontSize="13" Margin="0,0,0,-5"></Label>
            </StackPanel>
        </HierarchicalDataTemplate>
    </TreeView.Resources>
</TreeView>
4

1 回答 1

3
XmlDataProvider p = (XmlDataProvider)this.FindResource("myData");
p.XPath = string.Format("//Organizations/Organization[contains(@Title,\"{0}\")]/Layer[contains(@Title,\"{1}\")]", 
                        this.orgTitleFilter.Text, 
                        this.layerNameFilter.Text);
于 2013-01-25T17:49:38.177 回答