WPF Filter Datagrid

1.6k Views Asked by At

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. 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. 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;
 };
1

There are 1 best solutions below

1
On BEST ANSWER

Is your DataGrid bound to playersSource, or view? If you're doing the former, try the latter. :)