c# - WPF ComboBox Databound to a class -


should possible bind wpf combo box class. have class implements iemunerable , ienumerator, , contains list of objects, follows:

class myclass {     public string title { get; set; }     public string directory { get; set; }      public myclass(string title, string directory)     {         title = title;         directory = directory;     } }  class myclasses : ienumerable, ienumerator {     private list<myclass> allclasses;     private int position = 0;      public list<myclass> getclasses()     {         allclasses = new list<myclass>()         {             new myclass("example1", "dir1"),             new myclass("example2", "dir2")         };          return allclasses;     }       public ienumerator getenumerator()     {         return (ienumerator) this;     }      public object current     {                 {             return allclasses[position];         }     }      public bool movenext()     {         position++;         return (position < allclasses.count());                 }      public void reset()     {         position = -1;     } } 

so want bind wpf combobox. here’s have, doesn’t work (i instead list of type names of objects):

        allclasses.getclasses();          cbotest.itemssource = allclasses;         cbotitle.selectedvalue = "title"; 

can tell me how implement binding?

cbotitle.selectedvalue = "title"; 

should be

cbotitle.displaymemberpath = "title"; 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -