简体   繁体   English

派生类上的INotifyPropertyChanged

[英]INotifyPropertyChanged on a derived class

I've got a class which is also a table on a sqlite database on a Windows Phone 8 project. 我有一个类,它也是Windows Phone 8项目上sqlite数据库上的表。

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();
           }
       }
   }

}

And another class I use in my View which derives from Item. 我在View中使用的另一个类是从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
...
}

Now when the derived items are loaded my View doesn't seem to get updated. 现在,在加载派生项时,我的视图似乎没有更新。 How does change notification work on derived classes? 更改通知如何在派生类上工作?

you are firing the events in the constructor ... ie nothing will of hooked up to the events yet. 您正在构造函数中触发事件……也就是说,还没有任何东西可以关联到事件。

also you cant call events from the inherited class like this iirc. 您也不能从继承的类(如iirc)中调用事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM