2

I've used ICollectionView a few times and never had any problems... but I can't get this one to work.

In my constructor I do the following:

    _viewModels = new ObservableCollection<MyViewModel>();

    var icv = CollectionViewSource.GetDefaultView(_viewModels);
    MyCollectionView = icv; 

The one thing that I think is different is that I populate my _viewModels with a separate call. So with a button for example after the app loads. Even if I call MyCollectionView.Refresh() though at that time, and _viewModels has objects in it, MyCollectionView is still empty.

Should this work? If so what am I missing and what can I look for?

Nicros
  • 5,031
  • 12
  • 57
  • 101
  • *I've used ICollectionView a few times and never had any problems*... then just follow your earlier working examples. – Sheridan Dec 23 '14 at 10:21
  • I'm not sure about .net 4 but int 4.5 iv'e come to a conclusion that Refresh() , just does nothing . I just recreate it in the getter . – eran otzap Dec 23 '14 at 15:47
  • @Sheridan yep that's what I did. – Nicros Dec 23 '14 at 18:02
  • @eranotzap You hit it on the head. Refresh does indeed seem to do nothing- grabbing the view again seems to work. I wonder if it's been deprecated for ICollectionViewLiveShaping? Docs don't say it's deprecated though. Post this as an answer and I'll mark it. – Nicros Dec 23 '14 at 18:04

1 Answers1

0

It seems as if Refresh does nothing in .Net 4.5 i haven't tried it on 4 so i can't say for sure when it stopped working , if it ever did . What i like to do is :

     public ICollectionView MyCollectionView
     {
        get 
        {              
            return new CollectionView(SourceCollection); 
        }
     }
eran otzap
  • 12,293
  • 20
  • 84
  • 139