我被BindingList卡住,其中T是扩展A接口的接口。当我在绑定中使用这个bindingList时,只有来自T的属性是可见的,而来自继承的A接口的属性则不是。为什么会发生?它看起来像一个.net错误。这我需要我的2个项目共享一些通用功能。当PropertyChanged事件从baseImplementation隧道传输时,绑定List的PropertyDescriptor也是空的。 附加接口和实现。到底BindingList <T>其中T是实现其他接口的接口
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;
}
尽量不要在文件中附加代码。我们不需要整个项目。将你的例子分解成最小的程序,并将其作为文本/代码粘贴。 –
“不可见”是什么意思?如果你绑定了这些属性,它们可能会显示为不可访问,但这只是设计时绑定的结果,当你运行应用程序时,它应该都可以。 –
它们在绑定的网格中不可见,当从绑定列表触发ItemChanged事件时,如果它从BaseInterface处理属性,那么我得到null PropertyDescriptor。它在应用程序运行时不起作用。只需粘贴代码并查看。由于我的代表我不能发布图像 – user1079952