的IBindingList接口和BindingList類位於System.ComponentModel命名空間中定義,所以不嚴格有關Windows窗體。
您是否檢查過xamGrid是否支持綁定到ICollectionView源?如果是這樣,您可以使用此界面公開您的數據源並使用BindingListCollectionView備份它。
您還可以創建的ObservableCollection<T>
一個子類,並實現IBindingList的接口:
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class ObservableBindingList<T> : ObservableCollection<T>, IBindingList
{
// Constructors
public ObservableBindingList() : base()
{
}
public ObservableBindingList(IEnumerable<T> collection) : base(collection)
{
}
public ObservableBindingList(List<T> list) : base(list)
{
}
// IBindingList Implementation
public void AddIndex(PropertyDescriptor property)
{
throw new NotImplementedException();
}
public object AddNew()
{
throw new NotImplementedException();
}
public bool AllowEdit
{
get { throw new NotImplementedException(); }
}
public bool AllowNew
{
get { throw new NotImplementedException(); }
}
public bool AllowRemove
{
get { throw new NotImplementedException(); }
}
public void ApplySort(PropertyDescriptor property, ListSortDirection direction)
{
throw new NotImplementedException();
}
public int Find(PropertyDescriptor property, object key)
{
throw new NotImplementedException();
}
public bool IsSorted
{
get { throw new NotImplementedException(); }
}
public event ListChangedEventHandler ListChanged;
public void RemoveIndex(PropertyDescriptor property)
{
throw new NotImplementedException();
}
public void RemoveSort()
{
throw new NotImplementedException();
}
public ListSortDirection SortDirection
{
get { throw new NotImplementedException(); }
}
public PropertyDescriptor SortProperty
{
get { throw new NotImplementedException(); }
}
public bool SupportsChangeNotification
{
get { throw new NotImplementedException(); }
}
public bool SupportsSearching
{
get { throw new NotImplementedException(); }
}
public bool SupportsSorting
{
get { throw new NotImplementedException(); }
}
}
另外,還可以繼承BindingList<T>
並實現INotifyCollectionChanged接口。
什麼是XamDatagrid首先?你的意思是WPF工具箱datagrid?第三方組件?你能不能也請張貼一些示例代碼:) – Bruno 2011-06-06 16:01:23
@Bruno它是Infragistic的Datagrid版本 – Rachel 2011-06-06 16:11:31