c# - How to implement MVVM with the WPF treeview? -


i haven't worked wpf or mvvm pattern before.
want create simple document management system , using aforementioned technologies.

i've modeled hierarchical file system in database , want display in treeview.
eer-diagramm
can see each directory can have multiple sub-directories , multiple files in it.

i've read tutorials on topic , if understood them correctly should create model classes directory , file in data database stored directly.
example:

public class directory {     private int id;     public int id     {         { return id; }         set { id = value; }     }      private string name;     public string name     {         { return name; }         set { name = value; }     }      private int parent;     public int parent     {         { return parent; }         set { parent = value; }     }      private datetime datecreatedon;     public datetime datecreatedon     {         { return datecreatedon; }         set { datecreatedon = value; }     } } 

then each model class should have associated view-model class implements additional properties relevant describing ui element objects of class bound.
in case view-model class should have isexpanded , isselected property of treeviewitem.
need view-model class entire treeview contain collection of directorys , files should displayed.

my questions are:

  1. have understood mvvm concept correctly?
  2. which class, model or view-model, of directory should implement inotifypropertychanged interface?
  3. should view-model class of directory contain same properties model class or reference model-object in view-model class sufficient?
  4. if view-model class should contain same properties of model class again, whats best way make sure model-objects , associated view-model objects stay synchronized?

i hope question understandable , help. andahari

answer 1) yes.

answer 2) view-model should have inotifypropertychanged.

answer 3) yes. , should explicitly mapped. i.e.:

   this.property1 = model.property1 

answer 4) use same names, , see answer 3.

if use private-public property pair in view-model, use inotifypropertychanged in view-model, , map properties of model corresponding properties in view-model, should set.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -