c# - bind a combo-box to a List with "static" content and show content from database on WPF with MVVM -


i having combo box , want show when click on gender "female" or "male" , same time want read database "gender" has selected employee. so, want read , show on combo-box "sex" database when click on want show 2 different options have ("female" or "male"). problem know how bind combo-box can show content on observable collection, not know first how can bind property on , how can show same time 2 different choices 1 can choose.

thanks in advance!

keep observablecollection binding. sounds if that's working fine , responsible providing options want exposed in dropdown of combobox.

it sounds want show default sex property obtained database.

presumably, have sex property on datacontext implementing inotifypropertychanged

private string _sex;  public string sex {     { return _sex; }     set     {         if (_sex != value)         {             _sex = value;              onpropertychanged("sex");         }     } }  private void whatevermethodyouhavegettingdatafromdb() {     //... whatever needs ...      sex = // sex database... }  public event propertychangedeventhandler propertychanged;  private void onpropertychanged(string propertyname) {     if (propertychanged != null)         propertychanged(this, new propertychangedeventargs(propertyname)); } 

now have bindable property represents sex obtained database.

to push onto default exposed value in combobox, bind selectedvalue property.

<combobox itemssource="{binding --your observable collection--}"           selectedvalue="{binding sex}"/> 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -