我有了ObservableCollection
类型的DependencyProperty
绑定到一个observableCollection
自定义控制:集合依赖属性
<MyControl MyCollectionProperty = {Binding MyObservableCollection} ...
问题是增加了MyObservableCollection
不更新MyCollectionProperty
。
我需要完全取代MyObservableCollection
才能使其工作,例如,
MyObservableCollection = null;
MyObservableCollection = new ObservableCollection(){...}
有没有更好的方法来处理这个问题?
编辑:
public ObservableCollection<string> Columns
{
get { return (ObservableCollection<string>)GetValue(ColumnsProperty); }
set { SetValue(ColumnsProperty, value); }
}
public static readonly DependencyProperty ColumnsProperty =
DependencyProperty.Register("Columns", typeof(ObservableCollection<string>), typeof(MyControl),
new PropertyMetadata(new ObservableCollection<string>(), OnChanged));
你会发布你的依赖属性的定义吗?可能是在那里的东西... – 2013-02-22 01:13:02
是你的“MyControl”监视PropertyChanged或CollectionChanged,并且你监视你的可观察集合中的对象的PropertyChanged? – grantnz 2013-02-22 01:15:04
是的,在定义和处理程序中有一个回调CollectionChanged永远不会被解雇。由于我们正在讨论添加,我没有看到在项目上监听PropertyChanged的位置是相关的。 – user1604008 2013-02-22 01:34:34