wpf - When PropertyChanged called event PropertyChanged=null -


i have class derived inotifypropertychanged track property changes. properties bound treeview , needed perform searching in treeviewitems. when in properties setters this.onpropertychanged("isexpanded") called reason this.propertychanged == null when "isexpanded" bubbled root element of treeview. why null here , not null on deeper treeview elements? can solve issue? code cs:

    public class treeviewitemviewmodel:inotifypropertychanged     {         public event propertychangedeventhandler propertychanged;          protected virtual void onpropertychanged(string propertyname)         {             if (this.propertychanged != null)                 this.propertychanged(this, new propertychangedeventargs(propertyname));         }      ....................          bool _isexpanded;         public bool isexpanded         {             { return _isexpanded; }             set             {                 if (value != _isexpanded)                 {                     _isexpanded = value;                     this.onpropertychanged("isexpanded");                 }                  //expand till root                 if (_isexpanded && _parent != null)                     _parent._isexpanded = true;                  //lazy load children, if nessesary                 if (this.hasdummychild)                 {                     this.children.remove(dummychild);                     this.loadchildren();                 }             }          }          bool _isselected;         public bool isselected         {             { return _isselected; }             set             {                 if (value != _isselected)                 {                     _isselected = value;                     this.onpropertychanged("isselected");                 }             }         }     .............................     } 

my code xaml:

          <treeview itemssource="{binding areas}">                 <treeview.itemcontainerstyle>                     <style targettype="{x:type treeviewitem}">                         <setter property="isexpanded" value="{binding isexpanded, mode=twoway}" />                         <setter property="isselected" value="{binding isselected, mode=twoway}" />                         <setter property="fontweight" value="normal" />                         <style.triggers>                             <trigger property="isselected" value="true">                                 <setter property="fontweight" value="bold" />                             </trigger>                         </style.triggers>                     </style>                 </treeview.itemcontainerstyle>                 <treeview.resources>                     <hierarchicaldatatemplate                        datatype="{x:type vareas:areaviewmodel}"                        itemssource="{binding children}"                       >                         <stackpanel orientation="horizontal">                             <textblock text="{binding name}" />                         </stackpanel>                     </hierarchicaldatatemplate>                 </treeview.resources>             </treeview> 

the problem never subscribe event propertychanged. subscribe start work fine

this.propertychanged += areaviewmodel_propertychanged; 

void areaviewmodel_propertychanged(object sender, system.componentmodel.propertychangedeventargs e)     {         if (e.propertyname == "isexpanded")         {             //expand till root             if (this.isexpanded && this.parent != null)                 this.parent.isexpanded = true;              //lazy load children, if nessesary             if (this.hasdummychild)             {                 this.children.remove(dummychild);                 this.loadchildren();             }         }     } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -