的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