开发者

Finding all the ICollectionView's attached to a collection

开发者 https://www.devze.com 2022-12-19 16:40 出处:网络
We have multiple filters based on the same collection. i.e. we are displaying the same collection in a variety of ways. What i would like to be able to do is ask all of the CollectionViews to 开发者_运

We have multiple filters based on the same collection. i.e. we are displaying the same collection in a variety of ways. What i would like to be able to do is ask all of the CollectionViews to 开发者_运维百科refresh when a property changes (as the collection view will only refilter if items get added/removed from the collection). Is there a way to find all the collectionViews associated with a given collection. Is there a two way link between the collection view and the collection, or a way to determine this link.

P.S. I dont think the answer is

ICollectionView coll = CollectionViewSource.GetDefaultView(Collection);

as this will give me the default view for the collection, not all of the ICollectionViews asscoiated with the Collection.


If your collection is an ObservableCollection, you can do a ResettableObservableCollection.

public class ResettableObservablecollection<T>: ObservableCollection<T>
{
   //copy desired ctors

   public void ForceReset()
   {
       OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset));
   }
}

The ICollectionView that gets generated will be watching for that and refresh itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号