Win10 uwp rss reader

Source: Internet
Author: User
Tags try catch

Win10 uwp rss reader

RSS simple information aggregation (also called aggregate content) is a content packaging and delivery protocol widely used on the Internet based on XML standards. RSS (Really Simple Syndication) is a format used to describe and synchronize website content. It is the most widely used XML application. RSS builds a technical platform for rapid dissemination of information, making everyone a potential information provider. After an RSS file is published, the information contained in the RSS Feed can be directly called by other sites, and because the data is in a standard XML format, therefore, it can also be used in other terminals and services. It is a format for describing and synchronizing website content. RSS can be one of the following three interpretations: Really Simple Syndication; RDF (Resource Description Framework) Site Summary; Rich Site Summary. However, these three interpretations refer to the same Syndication technology.

I saw an rss feed in win10.me today. I don't know what it is.


Lin Zheng's book also said, but he uses HttpWebRequest <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Authorization + DQo8cHJlIGNsYXNzPQ = "brush: java;"> Windows.Web.Syndication.SyndicationClient client = new Windows.Web.Syndication.SyndicationClient(); Windows.Web.Syndication.SyndicationFeed feed;

Because the URL may be incorrect, Microsoft uses try catch

// Uri is written outside, so that the variable Uri uri = null is not found outside the try; // uri string uriString = "http://www.win10.me /? Feed = rss2 "; try {uri = new Uri (uriString);} catch (Exception ex) {throw ex ;}

There are many exceptions in network requests.

Try {// simulate http // client error may occur if no setting is set. setRequestHeader ("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"); feed = await client. retrieveFeedAsync (uri); foreach (Windows. web. syndication. syndicationItem item in feed. items) {displayCurrentItem (item) ;}} catch (Exception ex) {// Handle the exception here .}

We write a function to process every SyndicationItem.

        private void displayCurrentItem(Windows.Web.Syndication.SyndicationItem item)        {            string itemTitle = item.Title == null ? "No title" : item.Title.Text;            string itemLink = item.Links == null ? "No link" : item.Links.FirstOrDefault().ToString();            string itemContent = item.Content == null ? "No content" : item.Content.Text;            string itemSummary = item.Summary.Text + "";            reminder = itemTitle + "\n" + itemLink + "\n" + itemContent+"\n"+itemSummary+"\n";        }

Reminder is the notification display, which places each value not empty in StringBuilder

It looks like a lot of html. We can use WebUtility and Regex to get the text.

We can create a display title and click the display content.

Create a class rssstr, which stores the rss title and content

A list in viewModelObservableCollection

Interface MainPage

<Code class = "hljs xml"> <grid background = "{ThemeResource ApplicationPageBackgroundThemeBrush}"> <grid. rowdefinitions> <rowdefinition> </rowdefinition> <rowdefinition height = "auto"> </rowdefinition> </grid. rowdefinitions> <scrollviewer grid. row = "0" verticalscrollbarvisibility = "Auto"> <listview selectionchanged = "select" itemssource = "{x: Bind view. rsslist} "> <listview. itemtemplate> <datatemplate> <grid> <Grid. rowdefinitions> <rowdefinition> </grid. rowdefinitions> <textblock text = "{Binding title}"> </textblock> </grid> </datatemplate> </listview. itemtemplate> </listview> <! -- {Cke_protected} {C} % 3C! % 2D % 2D % 3 CTextBlock % 20Grid. row % 3D % 220% 22% 20 Text % 3D % 22% 7Bx % 3 ABind % 20view. reminder % 2 CMode % 3 DOneWay % 7D % 22% 20 TextWrapping % 3D % 22 Wrap % 22% 2F % 3E % 2D % 3E --> </scrollviewer> </grid> </code> <button grid. row = "1" margin = "10, 10, 10" content = "OK" click = "Button_Click"> <code class = "hljs xml"> </code> </button>

Create a page named rss_page

<Code class = "hljs mathematica"> <page. resources> <style x: key = "TextBlockStyle1" targettype = "TextBlock"> <Setter Property = "Margin" Value = "10, 10, 10, 10 "/> </style> </page. resources> <grid background = "{ThemeResource ApplicationPageBackgroundThemeBrush}"> <grid. rowdefinitions> <rowdefinition height = "auto"> <rowdefinition height = "auto"> </rowdefinition> </grid. rowdefinitions> <textblock style = "{StaticResource TextBlockStyle1}" grid. row = "0" text = "{x: Bind view. title} "> <textblock style =" {StaticResource TextBlockStyle1} "grid. row = "1" text = "{x: Bind view. summary} "> </textblock> </grid> </code> <button grid. row = "2" content = "OK" click = "Button_Click"> <code class = "hljs mathematica"> </code> </button>

Click on the list

        private void select(object sender, SelectionChangedEventArgs e)        {            Frame frame = Window.Current.Content as Frame;            frame.Navigate(typeof(rss_page), (ViewModel.rssstr)(sender as ListView).SelectedItem);        }

Rss_page viewModel uses rssstr

        protected override void OnNavigatedTo(NavigationEventArgs e)        {            view = e.Parameter as rssstr;            base.OnNavigatedTo(e);        }

Rss_page cannot scroll TextBlock. You can use ScrollViewer

<code class=" hljs mathematica">        <scrollviewer grid.row="1">            <textblock style="{StaticResource TextBlockStyle1}" grid.row="1" text="{x:Bind view.summary}" textwrapping="Wrap">       </textblock></scrollviewer></code>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.