0
我有一個數據網格,我想根據從組合框中選擇的值進行過濾。 datagrid的源是一個XML文件。以下是我正在使用的代碼。當我跟蹤代碼時,視圖過濾器正確地爲每行返回true和false,但datagrid永遠不會更新。我錯過了什麼簡單的事情?WPF Filter Datagrid
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;
};
您使用哪種XAML將XML綁定到網格?我懷疑綁定的collection和playersSource是不同的,因此有不同的默認視圖。 – mancaus 2011-02-16 22:06:41