我是 WPF 的新手,我想CollectionView
用我的ComboBox
控件过滤一些数据。
到目前为止我做了什么:
<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;
}
}
此代码成功地过滤了group1
我元素中包含文本的所有元素contact_grname
。
但是如何绑定到我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;
}