Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带组合框的WPF过滤器_C#_Wpf_Combobox_Filter - Fatal编程技术网

C# 带组合框的WPF过滤器

C# 带组合框的WPF过滤器,c#,wpf,combobox,filter,C#,Wpf,Combobox,Filter,我是WPF新手,我想用CollectionView和我的ComboBox控件过滤一些数据 到目前为止我所做的: 政务司司长: private int count=0; 无效筛选器(对象发送器、筛选器目标) { 如果(值==“”| |值==null) { e、 接受=正确; } 其他的 { System.Xml.xmlement ele=e.项为System.Xml.xmlement; string name=ele.SelectNodes(“/response/contacts/conta

我是WPF新手,我想用
CollectionView
和我的
ComboBox
控件过滤一些数据

到目前为止我所做的:


政务司司长:

private int count=0;
无效筛选器(对象发送器、筛选器目标)
{
如果(值==“”| |值==null)
{
e、 接受=正确;
}
其他的
{
System.Xml.xmlement ele=e.项为System.Xml.xmlement;
string name=ele.SelectNodes(“/response/contacts/contact/contact\u grname”)[count].InnerText;
计数+=1;
//MessageBox.Show(名称);
如果(名称==“组1”)e.已接受=真;
否则e.接受=错误;
}
}
此代码成功过滤my
contact_grname
元素中包含
group1
文本的所有元素

但是如何绑定到我的
组合框
,其中包含所有
联系人姓名
(XML绑定)


如果我理解正确,您希望将另一个组合框绑定到第一个组合框组中的项目

    <XmlDataProvider x:Key="TeleData" XPath="/response/contacts/contact" Source="C:\Data.xml" />
    <CollectionViewSource x:Key="TeleView" Source="{StaticResource TeleData}" >
        <CollectionViewSource.SortDescriptions>
            <scm:SortDescription PropertyName="contact_name" Direction="Ascending"  />
        </CollectionViewSource.SortDescriptions>
        <CollectionViewSource.GroupDescriptions>
            <dat:PropertyGroupDescription PropertyName="contact_grname"   />
        </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>

</Window.Resources>

<StackPanel>
    <ComboBox ItemsSource="{Binding Source={StaticResource TeleView}, Path=Groups}" DisplayMemberPath="Name" Name="comboGroups" />
    <ComboBox ItemsSource="{Binding ElementName=comboGroups, Path=SelectedItem.Items}" DisplayMemberPath="contact_name" Name="comboNames" />
</StackPanel>


结果:

一旦在
组合框中选择了一个项目
,根据所选项目过滤要显示的元素,调用
过滤器
方法,将在
组合框中选择的值传递给它

然后,使用以下命令刷新datagrid:

yourDataGrid.Items.Refresh()

以及具有以下功能的CollectionView:

yourCollectionView.Refresh();

此外,请阅读这篇文章,解释
CollectionView

的功能。嘿,你想用另一个组合框中所选组的项目填充另一个组合框吗?嗨!谢谢回复!否,不使用另一个组合框:-)我想使用在我的组合框中选择的项(contact_grname)过滤我的数据网格
yourCollectionView.Refresh();