How to add sublist in wpf using mvvm? -


namespace colourchanges {     public class group      {         public string name { get; set; } //its class adding parent list using group class     }      public class employeetree : inotifypropertychanged     {         public employeetree()         {             this.groupstaff = new list<group>();             groupstaff.add(new group { name = "designers" });             groupstaff.add(new group { name = "developers" });             groupstaff.add(new group { name = "managers" });  //here declaring list adding parent list         }          private list<group> _groupstaff;         public list<group> groupstaff         {             { return _groupstaff; }             set             {                 _groupstaff = value;                 raisepropertychanged("groupstaff");             }         } //creates list parentlist          private group _selectedgroupstaff;         public group selectedgroupstaff         {             { return _selectedgroupstaff; }             set             {                 _selectedgroupstaff = value;                 if (selectedgroupstaff.name == "designers")                 {                     city = "chennai";                     country = "india";                     email = "designer@gmail.com";                     mobileno = 9094117917;                     address = "annanagar";                 }                 else if (selectedgroupstaff.name == "developers")                 {                     city = "trichy";                     country = "india";                     email = "developer@gmail.com";                     mobileno = 9094667878;                     address = "koyambedu";                 }                 else if (selectedgroupstaff.name == "managers")                 {                     city = "salem";                     country = "india";                     email = "manager@gmail.com";                     mobileno = 9094154678;                     address = "arumbakkam";                 }                 raisepropertychanged("selectedgroupstaff");             }         }//for selecting parent list in order bind textbox           private string _city;         private string _country;         private string _email;         private long _mobileno;         private string _address; //properties of parent list bind textbox         public string city         {             { return _city; }             set             {                 _city = value;                 raisepropertychanged("city");             }         }         public string country         {             { return _country; }             set             {                 _country = value;                 raisepropertychanged("country");             }         }         public string email         {             { return _email; }             set             {                 _email = value;                 raisepropertychanged("email");             }         }         public long mobileno         {             { return _mobileno; }             set             {                 _mobileno = value;                 raisepropertychanged("mobileno");             }         }         public string address         {             { return _address; }             set             {                 _address = value;                 raisepropertychanged("address");             }         } ///raise property changed event handler code           public event propertychangedeventhandler propertychanged;         public void raisepropertychanged(string propertyname)         {             if (this.propertychanged != null)                 this.propertychanged(this, new propertychangedeventargs(propertyname));         }     } }    //how add sub list designers developers , managers in constructor  

let following model class

public class group  {  private string _city;  private string _country;  private string _email;  private long _mobileno;  private string _address;  public group()  {   items = new observablecollection<group>();  }  public observablecollection<group> items { get; set; } } 

and @ viewmodel's constructor, can add items.

public employeetree()  {     this.groupstaff = new list<group>();     group rootgroup = new group(){name ="manager"};     group childgroup = new group(){name = "developer"};     rootgroup.items.add(childgroup);     this.groupstaff.add(rootgroup);     } 

this hierarchical structure. hope looking this.

and xaml should this

<treeview name="grouptreeview">   <treeview.itemtemplate>    <hierarchicaldatatemplate itemssource="{binding items}">     <textblock text="{binding name}" />    </hierarchicaldatatemplate> </treeview.itemtemplate>  


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -