WPF TreeView data binding -


i new wpf, although have heard concepts of it, model-view-viewmodel. want start learning wpf doing small program.

in program have treeview display directories (e.g. documents, computer etc.). can develop class data, directorymodel

class directorymodel : inotifypropertychanged {     private directoryinfo directory;     private fileinfo file;      private directorymodel(directoryinfo directory)     {         //...     }      private directorymodel(fileinfo file)     {         //...     }      public static directorymodel[] rootdirs()     {         //...     }      public directorymodel[] subdirs()     {         //...     }      public directorymodel[] files()     {         //...     }      public override string tostring()     {         if (this.directory != null)             return this.directory.name;         else             return this.file.name;     }      public event propertychangedeventhandler propertychanged; } 

now want bind model tree view. have read several articles binding data, msdn , codeproject, still don't catch key! read creating binding in xaml, , there 1 writes <c:mydata x:key="mydatasource"/>, mydatasource come from? first letter not capitalized, assume variable of type, there no definition or declaration or mention this.

i have read this article, there many things not clear me (like itemtemplate, itemcontainerstyle etc.). feeling is, seems there many different ways binding, , different blogs or article use different approaches.

so question is, how define model class, , create varible of class , bind control (here tree view)? or want know, standard approach bind data in wpf, if there any?

to start can bind public properties (at moment have methods in vm). properties should implement property changed event. in view.xaml.cs in constructor:

this.datacontext = new directorymodel (); 

and in view.xaml have create bindings e.g.

<textblock text="{binding mypropertyfromviewmodel}"/> 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -