【问题标题】:How to send notification about the change of composite collection如何发送有关组合集合更改的通知
【发布时间】:2013-04-02 10:04:54
【问题描述】:

我有一个复合集合。从后面的代码修改其项目后,我希望视图得到更新。但我不知道如何通知视图。我尝试了INotifyCollectionChanged,但它对我不起作用。

    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));
    }

【问题讨论】:

    标签: wpf notifications compositecollection


    【解决方案1】:

    您的ScriptParameterComboItem 类必须实现INotifyPropertyChanged。所以当改变它的属性时,会通知监听器。使用ObservableCollection 有助于在将某些内容添加删除 时通知听众。不更改每个项目中的实际数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 2021-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 2018-11-06
      相关资源
      最近更新 更多