我是WPF的新手,我想用我的ComboBox
控件過濾一些數據,CollectionView
。帶組合框的WPF過濾器
我迄今所做的:
<CollectionViewSource x:Key="TeleView" Source="{StaticResource TeleData}" Filter="Filter" >
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="contact_name" Direction="Ascending" />
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<dat:PropertyGroupDescription PropertyName="contact_grname" />
</CollectionViewSource.GroupDescriptions>
CS:
private int count = 0;
void Filter(object sender, FilterEventArgs e)
{
if (value == "" || value == null)
{
e.Accepted = true;
}
else
{
System.Xml.XmlElement ele = e.Item as System.Xml.XmlElement;
string name = ele.SelectNodes("/response/contacts/contact/contact_grname")[count].InnerText;
count += 1;
//MessageBox.Show(name);
if (name == "group1") e.Accepted = true;
else e.Accepted = false;
}
}
此代碼成功地篩選我contact_grname
元素中與group1
文本的所有元素。
但如何綁定到我的ComboBox
其中包含所有contact_grnames
(XML綁定)?!
private void cmbGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
value = cmbGroup.SelectedValue.ToString();
lblGroupName.Content = "Groupname: " + value;
CollectionViewSource cvs = FindResource("TeleView") as CollectionViewSource;
}
嘿,所以你想在其他組合框中填充另一個組合框中的項目? –