Binding data to combobox in WPF -


i beginner in programming, wpf. have application in wpf. have changed connection .sdf database entity framework sqlcecommand. unfortunatelly, before had following code binding combobox.

<dockpanel grid.row="4">     <button x:name="loadbutton" height="20" tooltip="choose setting name load"    width="75" padding="2,2,2,2" margin="2,0,2,0" horizontalalignment="left" verticalalignment="center" content="load settings"  command="{binding loadsettingscommand}"/>      <combobox x:name="loadsettingscombobox" tooltip="choose setting name load" itemssource="{binding mode=oneway, path=settings/}" selectedvalue="{binding loadsettingname,  mode=onewaytosource}" selectedvaluepath="name" grid.column="1" >         <combobox.itemtemplate>             <datatemplate>                 <textblock horizontalalignment="center" text="{binding name, mode=twoway, updatesourcetrigger=propertychanged}"/>             </datatemplate>         </combobox.itemtemplate>     </combobox> </dockpanel> 

and:

list<setting> _settings; settings = new collectionview(_settings); 

and worked. after changing connection database there no error, combobox doesn't show data. before setting class generated entity framework. now, made own class setting. class should implement? can me?

vote answer if find helpful.

as per understanding if using setting data object need store observablecollection<>. use :

private observablecollection<settings> _settinglist = new observablecollection<settings>();     public observablecollection<settings> settinglist     {                 {             return this._settinglist;         }         set         {             if(value==null)             return;             this._settinglist = value;             //onpropertychanged(()=>this.settinglist); //it not required observablecollection<> notifies on collection changed.         }     } 

if implementing own setting class should implement inotifypropertychanged interface bind properties combobox item. below code reference:

public class settingsmodel : inotifypropertychanged {     #region inotifypropertychanded event implementation      public event propertychangedeventhandler propertychanged;      public void onpropertychanged<tproperty>(expression<func<tproperty>> propertyexpression)     {         propertychangedeventhandler handler = propertychanged;          if (null == handler)             return;          if (null != propertyexpression)         {             var e = new propertychangedeventargs(((memberexpression)propertyexpression.body).member.name);             handler(this, e);         }     }      public void onpropertychanged(string propertyname)     {         propertychangedeventhandler handler = propertychanged;          if (null != propertychanged)             handler(this, new propertychangedeventargs(propertyname));     }     #endregion } 

above implementation gives method onpropertychanged(string propertyname). need call method on "set" section of each property in class. whenever property value gets changed notify dependencyproperty of control.

hope you.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -