1
votes

Description: First I created an ObservableCollection which is accessed via the public property MyCollection. Now if I bind my DataGrid UI to MyCollection it will recognize collection changes, but not if MyCollection itself changes (ie. UpdateCollection method). To solve this issue I applied the familiar 'PropertyChanged("MyCollection")' to the MyCollection Property.

Now I found the need to group my DataGrid Content which requires a Collection View layer. When I added and binded to the CollectionView the UI no longer updates when MyCollection gets re-assigned. I read that only CollectionChanged propagate from the Source to the View. I guess in my case it is the PropertyChange on MyCollection that needs to somehow trigger a CollectionChanged event on the Source or View.

Question: How can I get a re-assigmend on MyCollection to trigger a UI update, which is bound to a View of MyCollection?

Note: The reason for re-assigning MyCollection is due to a Modular MEF/MVVM architecture.

public class MyViewModel
{
  public MyViewModel()
  {
    MyCollectionViewSource = new CollectionViewSource() { Source = MyCollection};
    // The DataGrid is bound to this ICollectionView
    MyCollectionView = MyCollectionViewSource.View;
  }

  // Collection Property
  // NotifyPropertyChanged added specifically to notify of MyCollection re-assignment
  ObservableCollection<MyObject> _MyCollection;
  public ObservableCollection<MyObject> MyCollection
  {
    get {return _MyCollection;}
    set {if (value != _MyCollection)
            {_MyCollection = value;
            NotifyPropertyChanged("MyCollection");}}
  }

  public MyCollectionViewSource PropertiesCollectionViewSource { get; private set; }
  public ICollectionView = MyCollectionView { get; private set; }

  // Method updates MyCollection itself (Called via ICommand from another ViewModel)
  public void UpdateCollection(ObservableCollection<MyObject> NewCollection)
  {
    MyCollection = NewCollection;
  }
}

Thanks,

1
Can you reassign MyCollectionViewSource.Source too? I don't see that Properties have changed. - LPL
My apologies that was a typo. I have edited the question, the Source property should equal MyCollection. - aidesigner

1 Answers

0
votes

Have a look at the Active Grouping Collection, its aimed at a different problem but might solve yours.

Building a smarter WPF CollectionView

Active Collection View on CodePlex