我卡在了BindingList上,其中T是扩展A接口的接口。当我在绑定中使用这个bindingList时,只有T的属性可见,而从继承的A接口继承的属性则不可见。为什么会发生这种情况?看起来像是一个.NET的bug。这对我的两个项目来说是必要的,以共享一些公共功能。同时,当PropertyChanged事件从基本实现中传递时,绑定列表的PropertyDescriptor为空。附加接口和实现。最后是SetUp方法。
interface IExtendedInterface : IBaseInterface
{
string C { get; }
}
interface IBaseInterface : INotifyPropertyChanged
{
string A { get; }
string B { get; }
}
public class BaseImplementation : IBaseInterface
{
public string A
{
get { return "Base a"; }
}
public string B
{
get { return "base b"; }
protected set
{
B = value;
OnPropertyChanged("B");
}
}
protected void OnPropertyChanged(string p)
{
if (PropertyChanged != null)
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(p));
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
}
public class ExtendedImplementation : BaseImplementation, IExtendedInterface
{
public string C
{
get { return "Extended C"; }
}
}
private void SetupData()
{
BindingList<IExtendedInterface> list = new BindingList<IExtendedInterface>();
list.Add(new ExtendedImplementation());
list.Add(new ExtendedImplementation());
dataGridView1.DataSource = list;
}