c# - WPF Databinding to combobox -


i'm having issues databinding combobox. other bindings work fine. tell me i'm doing wrong here.

 class bank     {         public string bankcode{get; set;}         public string bankname { get; set; }             public observablecollection <bankbranch> branches;      }     class bankbranch     {         public string branchcode { get; set; }         public string branchname { get; set; }     }              bank b = new bank{                 bankcode="1",                 bankname="bank1",                 branches = new observablecollection<bankbranch>(){                     new bankbranch(){branchcode="11", branchname="location1"},                     new bankbranch(){branchcode="11", branchname="location12"}                 },              };             bankpanel.datacontext = b;   <stackpanel x:name="bankpanel">         <stackpanel orientation="horizontal">             <textblock >bank code</textblock>             <textbox text="{binding bankcode}" width="100"/>         </stackpanel>         <stackpanel orientation="horizontal">             <textblock >bank name</textblock>             <textbox text="{binding bankname}" width="100"/>         </stackpanel>         <stackpanel orientation="horizontal">             <textblock >bank branches</textblock>              <combobox itemssource="{binding branches}" displaymemberpath="branchname"   selectedvaluepath="branchname"   width="100">              </combobox>         </stackpanel>     </stackpanel> 

you should binding properties not fields.

in case branches declared field.

try following code:

class bank {     public string bankcode { get; set; }     public string bankname { get; set; }     public observablecollection<bankbranch> branches { get; set; } } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -