Programering af mobile enheder Windows Phone Rss Feed
Reference til System.ServiceModel.Syndication.dll Der findes en færdig klasse til RSS feed, men man skal selv ”fiske” den nødvendig reference til dll for at kunne få tilgang.
WebClient kan hente data fra url (text, htlm, xml……) private void buttonLoadRss_Click(object sender, RoutedEventArgs e) { WebClient wc = new WebClient(); wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted); wc.OpenReadAsync(new Uri(" } void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { // metode kaldes når read er færdig // e.Result indeholder i dette tilfælde en stream }
RSS feed fås fra XML reader til SyndicationFeed private void buttonLoadRss_Click(object sender, RoutedEventArgs e) { WebClient wc = new WebClient(); wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted); wc.OpenReadAsync(new Uri(" } void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { // System.ServiceModel.Syndication.dll skal hentes via browser using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(e.Result)) { System.ServiceModel.Syndication.SyndicationFeed feed = System.ServiceModel.Syndication.SyndicationFeed.Load(reader); var items = feed.Items; listBox1.ItemsSource = items;// items kan nu fx vises i ListBox }
xaml eksempel på listbox med template for databinding til RSS feed
Links How to create a basic RSS reader for Windows Phone Data Binding (WPF) Data Binding Overview c# - WP7 SyndicationFeed - Stack Overflow