c# - Wpf: How can I know if TreeView is Updated? -


i using wpf treeview, in can add treeviewitems dynamically. there way know when tree updated? tried collectionchanged event of observablecollection binded treeview didn't work.

edit:

my code in this:

class temp {     public void load()     {         derivea d1 = new derivea();         deriveb d2 = new deriveb();         deriveb d3 = new deriveb();         derivec d4 = new derivec();         derivec d5 = new derivec();         d1.items.add(d2);         d1.items.add(d3);         d2.items.add(d4);         d2.items.add(d5);          list = new observablecollection<object>();         list.add(d1);         tree.itemssource = list;          derivec d6 = new derivec();         d3.items.add(d6);        //at point, want know list got updated     }      public observablecollection<object> list     {         get;         set;     } }  class base {     observablecollection<base> items = new observablecollection<base>(); }  class derivea : base { }  class deriveb : base { }  class derivec : base { } 

how can find when list property updated @ level?

what sourceupdated event?


edit sourceupdated event doesn't fire, tried observablecollection.collectionchanged , ok, ask give little code of yours, here have tested, hope helps:

public partial class window1 : window {     observablecollection<string> items = new observablecollection<string>()     {         "string1","string2","string3","string4","string5"     };     public window1()     {         initializecomponent();         datacontext = this;         tree.itemssource = items;         items.collectionchanged += new system.collections.specialized.notifycollectionchangedeventhandler(items_collectionchanged);     }      void items_collectionchanged(object sender, system.collections.specialized.notifycollectionchangedeventargs e)     {         messagebox.show("event raised");     }       private void btnadditem_click(object sender, routedeventargs e)     {         items.add("string6");     } } 

and xaml

<stackpanel orientation="vertical">             <treeview x:name="tree" />             <button x:name="btnadditem" click="btnadditem_click" content="additem" /> </stackpanel> 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -