简体   繁体   English

WPF筛选器数据网格

[英]WPF Filter Datagrid

I have a datagrid that I want to filter based on a value selected from a combobox. 我有一个要根据从组合框中选择的值进行过滤的数据网格。 The source of the datagrid is an XML file. 数据网格的源是一个XML文件。 Below is the code I am using. 下面是我正在使用的代码。 When I trace the code the view filter is returning true and false correctly for each row but the datagrid never updates. 当我跟踪代码时,视图过滤器为每一行正确返回true和false,但是datagrid从不更新。 What simple thing am I missing? 我缺少什么简单的东西?

ComboBoxItem typeItem = (ComboBoxItem)cbPositionFilter.SelectedItem;
String position = typeItem.Content.ToString();

IEnumerable<XElement> playersSource = ((XContainer)AllPlayers.DataContext).Descendants("Player");
ICollectionView view = CollectionViewSource.GetDefaultView(playersSource);

 view.Filter = delegate(object item)
 {
       bool match = ((XElement)(item)).Element("position").Value == position;
       return match;
 };

Is your DataGrid bound to playersSource , or view ? 您的DataGrid是否绑定到playersSourceview If you're doing the former, try the latter. 如果您正在使用前者,请尝试使用后者。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM