我只是偶然发现了DataGrid
WPF 中的一种行为,坦率地说,我不知道我是否做错了什么或者它是 WPF 的标准行为DataGrid
。
所以我有一个接口,我们称之为IItem。IItem 有几个属性(名称、活动、时间戳)。这个接口继承自另一个接口,我们称之为 IBaseItem。IBaseItem 还具有属性(Id、Selected、Active、Timestamp)。所以我希望当我DataGrid
在 XAML 中创建 aAutoGenerateColumns=true
并且绑定源是 a时List<IItem>
,它也会生成 Id 和 Selected 列。
相反,它仅将 Name、Active 和 Timestamp 属性生成为列。并且 Name 不可编辑(尽管它具有 setter 属性),但 Active 是。
public interface IBaseItem : INotifyPropertyChanged
{
bool Selected { get; set; }
int Id { get; }
bool Active { get; set; }
DateTime Timestamp { get; set;}
}
public interface IItem: IBaseItem, IEditableObject
{
string Name { get; set; }
new bool Active { get; set; }
new DateTime Timestamp { get; }
}
但是,如果我打破继承链并将 IItem 作为单独的接口,然后瞧,名称变得可编辑。
我不明白为什么继承把事情搞砸了。任何人都可以启发我吗?