我坚持使用 BindingList,其中 T 是扩展 A 接口的接口。当我在绑定中使用这个 bindingList 时,只有来自 T 的属性是可见的,而来自继承的 A 接口的属性不可见。为什么会这样?它看起来像一个 .net 错误。我需要我的 2 个项目来共享一些通用功能。当从 baseImplementation 传输 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;
}