My CollectionViewSource is not picking up changes

空扰寡人 提交于 2019-12-04 15:13:00

If you are "newing" rows then any setting on the prior rows is gone. If you clear (not new) the rows then I think they will hold the setting.

And you don't even want Rows = rows in update. After assign rows then.

NotifyPropertyChange("Rows"); 

So the UI know to update

If you are going to new then reassign

collectionView = CollectionViewSource.GetDefaultView(TableView.ItemsSource);
collectionView.SortDescriptions.Clear();
collectionView.SortDescriptions.Add(new SortDescription(propertyName, direction));

Maybe

private List<TableRow> rows = new List<TableRow>();  

and have that the only place you new it

If an item property value involved in one of the grouping, sorting and filtering operations is updated, then the sorting/grouping/filtering will not be done again.

WPF 4.5 introduce a feature called live shaping which shapes the collection view in live.

See this article for more info.

The answer is to reapply the sort descriptions after the update, as in:

collectionView = CollectionViewSource.GetDefaultView(TableView.ItemsSource);  
collectionView.SortDescriptions.Clear();
collectionView.SortDescriptions.Add(new SortDescription(propertyName, direction));

Then the sorting isn't lost. Refresh on the collection view doesn't help.

Did you try to do CollectionView.Refresh() after your update?

If this does not help then I think your problem occurs because you change the source of your CollectionView by assigning new value to your Rows list.

I don't know if it is possible to your code but don't assign new list just clear your previous one and insert new rows there.

if (Rows != null)
   Rows.Clear();
   Rows.TrimExcess();
else
   Rows = new List<TableRow>();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!