c# - Windows phone 8 RSS live tile -
im trying show newest feed item text in live tile rss, when run app, there no feed text inside live tile. hope there can help. thanks.
app.xaml.cs:
private void application_launching(object sender, launchingeventargs e) { var taskname = "windowsphoneblogsta"; periodictask periodictask = scheduledactionservice.find(taskname) periodictask; if (periodictask != null) scheduledactionservice.remove(taskname); periodictask = new periodictask(taskname) { description = "periodic task update tile of <your app>." }; try { scheduledactionservice.add(periodictask); #if debug scheduledactionservice.launchfortest(taskname, timespan.fromseconds(30)); #endif } catch (invalidoperationexception) { } }
scheduledagent.cs:
public class scheduledagent : scheduledtaskagent { /// <remarks> /// scheduledagent constructor, initializes unhandledexception handler /// </remarks> static scheduledagent() { // subscribe managed exception handler deployment.current.dispatcher.begininvoke(delegate { application.current.unhandledexception += unhandledexception; }); } /// code execute on unhandled exceptions private static void unhandledexception(object sender, applicationunhandledexceptioneventargs e) { if (debugger.isattached) { // unhandled exception has occurred; break debugger debugger.break(); } } /// <summary> /// agent runs scheduled task /// </summary> /// <param name="task"> /// invoked task /// </param> /// <remarks> /// method called when periodic or resource intensive task invoked /// </remarks> protected override void oninvoke(scheduledtask task) { webclient client = new webclient(); client.downloadstringcompleted += (s, e) => { downloadstringcompleted(s, e); notifycomplete(); }; client.downloadstringasync(new uri("http://blogs.windows.com/windows_phone/b/windowsphone/rss.aspx")); } private void downloadstringcompleted(object sender, downloadstringcompletedeventargs e) { if (e.error == null) { stringreader stringreader = new stringreader(e.result); xmlreader xmlreader = xmlreader.create(stringreader); syndicationfeed feed = syndicationfeed.load(xmlreader); var latestarticle = feed.items.firstordefault(); var tile = shelltile.activetiles.firstordefault(); if (tile != null) { var tiledata = new fliptiledata(); tiledata.title = "windows phone blog"; var content = latestarticle.title.text + " - " + latestarticle.summary.text; var image = new uri("http://imageservice.nordjyske.dk/images/nordjyske.story/2012_07_15/7280794c-78e6-4830-8ea5-e19934f52a55.jpg?maxwidth=500"); tiledata.backcontent = content; tiledata.backgroundimage = image; tiledata.widebackcontent = content; tiledata.widebackgroundimage = image; tile.update(tiledata); } } } }
Comments
Post a Comment