silverlight - listbox not updating content when data source changes -


i'm working on large wp7 project, , current task implement offline functionality.

i've got listbox should display items when device connected internet, , display empty view otherwise.

i've got event handler wired fires when connectivity changes, retrieve neccesary data listbox if i've got connection.

the problem when run app in offline mode, , turn wi-fi on, data listbox updates not ui itself

here xaml:

<listbox name="lstitemcategories" itemssource="{binding itemcategories, mode=twoway}"  selecteditem="{binding selecteditemcategory, mode=twoway}" margin="0,-15,0,60" tap="lstitemcategories_tap">                     <listbox.itemtemplate>                         <datatemplate>                             <stackpanel orientation="horizontal" margin="0,0,0,0" height="78" width="432">                                 <image height="70" width="70" horizontalalignment="right" name="image1" stretch="uniform"  source="{binding imagepath}" />                                 <listboxitem toolkit:tilteffect.istiltenabled="true">                                     <textblock text="{binding description}" verticalalignment="center" textwrapping="wrap" style="{staticresource phonetextextralargestyle}" foreground="{staticresource darkgrey}"/>                                 </listboxitem>                             </stackpanel>                         </datatemplate>                     </listbox.itemtemplate>                 </listbox> 

in viewmodel i've got observablecollection binding:

    public observablecollection<itemcategory> itemcategories     {         { return itemcategories; }         set         {             itemcategories = value;             notifypropertychanged("itemcategories");         }     } 

and i've got backgroundworker retrieves items need once device connected internet, , runworkercompleted method:

void itemcategoryworker_runworkercompleted(object sender, runworkercompletedeventargs e) {     app.itemcategories = (list<itemcategory>)e.result;      itemcategories = new observablecollection<itemcategory>(app.itemcategories); } 

so itemcategories property wired ui updated, not ui itself

figured out. change itemcategories must invoked on ui thread:

((mainview)view).dispatcher.begininvoke(() =>                 {                     itemcategories = new observablecollection<itemcategory>(app.itemcategories);                 }); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -