Provide a Collection as source to property in WPF Propertygrid -


i have following property of type string.

[category("general")] [displayname("book name")] public string bookname { //getter;   //setter; } 

when binding object containing property propertygrid, provide list of type string source.

list<string> booksource = new list<string>(); 

when property of type enum, automatically populates combobox, want acheive same functionality through collection.

edit: expanded:

enum booktype     {         novel = 0,         magazine = 1     }      class class1     {         string _bookname = "book 1";         booktype _booktype = booktype.magazine;          [category("general")]         [displayname("book name")]         public string bookname         {             { return this._bookname; }             set { this._bookname = value; }         }          [category("general")]         [displayname("book type")]         public booktype booktype         {             { return this._booktype; }             set { this._booktype = value; }         }     }       public partial class mainwindow : window     {          public mainwindow()          {              initializecomponent();              class1 obj = new class1();              this.wpfpropertygrid.selectedobject = obj;          }      } 

for above code, propertygrid displays combobox items "magazine" , "novel" property booktype , textbox text "book 1" property bookname. want property bookname displayed combobox can explicitly provide source. bind list {"book 1","book 2","book 3"} property bookname, user can select 1 of them.

better late never ;-)

with propertygrid extended wpf toolkit can way:

enum booktype {     novel = 0,     magazine = 1 }  public class bookitemssource : iitemssource {     public itemcollection getvalues()     {         var books = new itemcollection();         books.add("book 1");         books.add("book 2");         books.add("book 3");         return books;     } }  public class class1 {     string _bookname = "book 1";     booktype _booktype = booktype.magazine;      [category("general")]     [displayname("book name")]     [itemssource(typeof(bookitemssource))]     public string bookname     {         { return this._bookname; }         set { this._bookname = value; }     }      [category("general")]     [displayname("book type")]     public booktype booktype     {         { return this._booktype; }         set { this._booktype = value; }     } }  public partial class mainwindow : window {      public mainwindow()      {          initializecomponent();          class1 obj = new class1();          this.wpfpropertygrid.selectedobject = obj;      }  } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -