c# - Windows phone refresh/update listbox items -


i have problem rss feed app. when app launches, listbox gets feeds , show them in listbox, when press refresh button listbox never updates, show same items again, if close app, , relaunch it, show latest feeds. hope there can help. thanks.

mainwindow.xaml:

<listbox grid.row="1" name="feedlistbox" scrollviewer.verticalscrollbarvisibility="auto" selectionchanged="feedlistbox_selectionchanged">                 <listbox.itemtemplate>                     <datatemplate>                         ...                         ...                     </datatemplate>                 </listbox.itemtemplate>             </listbox> 

mainwindow.cs:

private void appbarrefresh_click(object sender, eventargs e) {     feedlistbox.itemssource = null;      getfeed(isolatedstoragesettings.applicationsettings["key"].tostring()); }  private void getfeed(string rss) {     webclient webclient = new webclient();      webclient.downloadstringasync(new system.uri(rss));     webclient.downloadstringcompleted += new downloadstringcompletedeventhandler(webclient_downloadstringcompleted); }  private void webclient_downloadstringcompleted(object sender, downloadstringcompletedeventargs e) {     if (e.error != null)     {         deployment.current.dispatcher.begininvoke(() =>         {             messagebox.show(e.error.message);         });     }     else     {         this.state["feed"] = null;         this.state.clear();         this.state["feed"] = e.result;          updatefeedlist(e.result);     } }  private void updatefeedlist(string feedxml) {     stringreader stringreader = new stringreader(feedxml);     xmlreader xmlreader = xmlreader.create(stringreader);     syndicationfeed feed = syndicationfeed.load(xmlreader);      deployment.current.dispatcher.begininvoke(() =>     {         feedlistbox.itemssource = feed.items;     });     ; } 

upd comments:

in onnavigatedto method run code:

if (this.state.containskey("feed"))  {      if (feedlistbox.items.count == 0)      {          updatefeedlist(state["feed"] string);      }  } 

first of update method:

private void getfeed(string rss) {     //register event handler first, call async method     webclient webclient = new webclient();     webclient.downloadstringcompleted += new downloadstringcompletedeventhandler(webclient_downloadstringcompleted);     webclient.downloadstringasync(new system.uri(rss));  } 

update:

looks request cached os. can add random text url.

webclient.downloadstringasync(new system.uri(rss + "?disablecache="+environment.tickcount));  

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -