wpfnotificationscompositecollection

How to send notification about the change of composite collection


I've got a composite collection. After modifications on its items from code behind I want the View to get updated. But I don't know how to notify the view. I tried the INotifyCollectionChanged, but it didn't work for me.

    protected ObservableCollection<ScriptParameterComboItem> cItems

    public virtual CompositeCollection CItems
    {
        get
        {
            return new CompositeCollection {new CollectionContainer {Collection = cItems}};
        }
    }

    public void ConvertValue(params object[] parameters)
    {
        string newAverageOption = DisplayValueConverter.Convert(1, parameters);
        var enumItem = cItems[1];
        enumItem.Value = newAverageOption;
        RaiseCollectionChanged("CItems");
    }


    protected void RaiseCollectionChanged(string property)
    {
        if(CollectionChanged != null)
            CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add));
    }

Solution

  • Your ScriptParameterComboItem class must implement INotifyPropertyChanged. So when changing it's properties, listeners will be notified. Using ObservableCollection helps listeners to be notified when something is added to the collection or removed from. Not changing the actual data within every single item.