C# 派生类上的INotifyPropertyChanged
我有一个类,它也是WindowsPhone8项目中sqlite数据库上的一个表C# 派生类上的INotifyPropertyChanged,c#,xaml,inotifypropertychanged,C#,Xaml,Inotifypropertychanged,我有一个类,它也是WindowsPhone8项目中sqlite数据库上的一个表 public class Item : INotifyPropertyChanged { private int _itemID; private string _name; [PrimaryKey, AutoIncrement] public string ItemID { get { return _barcode; } set {
public class Item : INotifyPropertyChanged
{
private int _itemID;
private string _name;
[PrimaryKey, AutoIncrement]
public string ItemID
{
get { return _barcode; }
set
{
if (value != _itemID)
{
_itemID = value;
OnPropertyChanged();
}
}
}
[MaxLength(100)]
public string Name
{
get { return _name; }
set
{
if (value != _name)
{
_name = value;
OnPropertyChanged();
}
}
}
}
我在视图中使用的另一个类是从Item派生的
public class SubItem : Item, INotifyPropertyChange
{
public class SubItem() {}
public class SubItem(Item item)
{
this.ItemID = item.ItemID;
this.Name = item.Name;
}
// Other properties implementing INPC
...
}
现在,当加载派生项时,我的视图似乎没有得到更新。更改通知如何在派生类上工作?您正在构造函数中触发事件。。。还没有什么能与这些事件联系起来
您也不能像这样从继承类调用事件。您能展示OnPropertyChanged的实现吗?仅供参考,如果基类实现了它,您不需要在派生类中指定接口。是的,Bort,这是一个输入错误。但是在那里指定它没有错。特别是当你想依靠它这样的行为时——有时会节省很多f12'ing。