1 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊
為了具備ListView自動(dòng)綁定到您的收藏,您必須實(shí)現(xiàn)這兩個(gè) INotifyCollectionChange 和 IList(注:這就是非通用的IList)。
如果您修改示例代碼以便您的自定義列表類(lèi)實(shí)現(xiàn)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觸發(fā)按鈕單擊事件時(shí)設(shè)置。
- 1 回答
- 0 關(guān)注
- 228 瀏覽
添加回答
舉報(bào)