1 回答
TA贡献1831条经验 获得超10个赞
为了具备ListView自动绑定到您的收藏,您必须实现这两个 INotifyCollectionChange 和 IList(注:这就是非通用的IList)。
如果您修改示例代码以便您的自定义列表类实现IList:
public class MyWrapperList<T> : IList<T>, INotifyPropertyChanged, INotifyCollectionChanged, IList
{
//... all your existing code plus: (add your own implementation)
#region IList
void ICollection.CopyTo(Array array, int index) => throw new NotImplementedException();
bool IList.IsFixedSize => throw new NotImplementedException();
bool IList.Contains(object value) => throw new NotImplementedException();
int IList.IndexOf(object value) => throw new NotImplementedException();
void IList.Insert(int index, object value) => throw new NotImplementedException();
void IList.Remove(object value) => throw new NotImplementedException();
int IList.Add(object value) => throw new NotImplementedException();
public bool IsSynchronized => throw new NotImplementedException();
public object SyncRoot { get; } = new object();
object IList.this[int index] {
get => this[index];
set => this[index] = (T) value;
}
#endregion
}
然后在CollectionChanged触发按钮单击事件时设置。
- 1 回答
- 0 关注
- 213 浏览
添加回答
举报