使用聚合而不是多继承:
class MyCollection<T> : DependencyObject, ICollection<T>
{
// Inner collection for call redirections.
private Collection<T> _collection;
#region ICollection<T> Members
public void Add(T item)
{
this._collection.Add(item);
}
public void Clear()
{
this._collection.Add(clear);
}
// Other ICollection methods ...
#endregion
#region MyProperty Dependency Property
public int MyProperty
{
get
{
return (int)this.GetValue(MyCollection<T>.MyPropertyProperty);
}
set
{
this.SetValue(MyCollection<T>.MyPropertyProperty, value);
}
}
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty",
typeof(int),
typeof(MyCollection<T>),
new FrameworkPropertyMetadata(0));
#endregion
}
这确实有可能使用DP,但其编写的ICollection的方法那种取消不必编写的INPC的优势 – David 2011-03-24 13:18:54