Monday, 15 March 2010

c# - Binding issue MVVM -



c# - Binding issue MVVM -

i have listbox populated through viewmodel , datatemplate in have binding. problem binding in datatemplate not working. here code:

viewmodel:

private void notifypropertychanged(string propertyname) { propertychangedeventhandler handler = propertychanged; if (null != handler) { handler(this, new propertychangedeventargs(propertyname)); } } #endregion private string strheadertext; public string headertext { { if (null != this.trips) { if (null != this._trips.name) { homecoming this._trips.name; } } homecoming "trip"; } set { this.strheadertext = value; } } public triptypeviewmodel() { this.triptypeviewmodeldatasource.clear(); foreach (triptype tt in tripsresponsetypeviewmodeldatasource.firstordefault().trip) { this.triptypeviewmodeldatasource.add(tt); } } ... private observablecollection<triptype> triptypeviewmodeldatasource; public observablecollection<triptype> triptypeviewmodeldatasource { { if (null == this.triptypeviewmodeldatasource) { this.triptypeviewmodeldatasource = new observablecollection<triptype>(); } homecoming this.triptypeviewmodeldatasource; } }

here view

<listbox x:name="itemslb" itemssource="{binding triptypeviewmodel.triptypeviewmodeldatasource}"> <listbox.itemtemplate> <datatemplate> <button content="{binding triptypeviewmodel.headertext}" width="auto" height="auto"/> </datatemplate> </listbox.itemtemplate> </listbox>

c# xaml mvvm binding windows-phone

No comments:

Post a Comment