西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
軟件
軟件
文章
搜索

首頁編程開發(fā)其它知識 → Windows 8 應(yīng)用開發(fā)開發(fā)之RSS 閱讀器實例

Windows 8 應(yīng)用開發(fā)開發(fā)之RSS 閱讀器實例

相關(guān)軟件相關(guān)文章發(fā)表評論 來源:西西整理時間:2013/2/15 20:07:40字體大。A-A+

作者:西西點擊:3次評論:0次標簽: RSS閱讀器

NetPlay Instant Demov10.00.08免費版
  • 類型:屏幕錄像大小:28.7M語言:中文 評分:10.0
  • 標簽:
立即下載

先上運行截圖:

簡單說明:右側(cè)主要內(nèi)容的顯示使用了瀏覽器控件WebView,另外,一些說明放在了代碼注釋中。

本應(yīng)用只有一張頁面MainPage

前臺代碼如下:
XAML

 1 <Page
 2     x:Class="Win8RssReader.MainPage"
 3     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 4     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 5     xmlns:local="using:Win8RssReader"
 6     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 7     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 8     mc:Ignorable="d">
 9     <Page.Resources>
10         <Style TargetType="TextBlock">
11             <Setter Property="FontSize" Value="20"/>
12             <Setter Property="IsTextSelectionEnabled" Value="True"/>
13             <Setter Property="VerticalAlignment" Value="Center"/>
14         </Style>
15         <GridLength x:Key="height1">30</GridLength>
16     </Page.Resources>
17 
18     <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
19         <Grid.ColumnDefinitions>
20             <ColumnDefinition Width="300"/>
21             <ColumnDefinition Width="*"/>
22         </Grid.ColumnDefinitions>
23         <Grid>
24             <Grid.RowDefinitions>
25                 <RowDefinition Height="{StaticResource height1}"/>
26                 <RowDefinition Height="50"/>
27                 <RowDefinition Height="{StaticResource height1}"/>
28                 <RowDefinition Height="{StaticResource height1}"/>
29                 <RowDefinition Height="{StaticResource height1}"/>
30                 <RowDefinition Height="*"/>
31             </Grid.RowDefinitions>
32             <TextBox x:Name="txtFeedUri" Width="300" Text="http://www.cnblogs.com/rss"/>
33             <Button x:Name="btnGetFeed" Content="加載RSS" Click="btnGetFeed_Click" Grid.Row="1"/>
34             <StackPanel Orientation="Horizontal" Grid.Row="2">
35                 <TextBlock Text="提示信息:"/>
36                 <TextBlock x:Name="txtMsg" Text="暫無" />
37             </StackPanel>
38             <StackPanel Orientation="Horizontal" Grid.Row="3">
39                 <TextBlock Text="RSS標題:"/>
40                 <TextBlock x:Name="txtFeedTitle" Text="暫無" />
41             </StackPanel>
42             <StackPanel Orientation="Horizontal" Grid.Row="4">
43                 <TextBlock Text="內(nèi)容條數(shù):"/>
44                 <TextBlock x:Name="txtCount" Text="暫無" />
45             </StackPanel>
46             <ListBox x:Name="listTitle" SelectionChanged="listTitle_SelectionChanged" Grid.Row="5">
47                 <ListBox.ItemTemplate>
48                     <DataTemplate>
49                         <TextBlock Text="{Binding Title.Text}" TextWrapping="Wrap"/>
50                     </DataTemplate>
51                 </ListBox.ItemTemplate>
52             </ListBox>
53         </Grid>
54         <Grid Grid.Column="1">
55             <Grid.RowDefinitions>
56                 <RowDefinition Height="{StaticResource height1}"/>
57                 <RowDefinition Height="*"/>
58             </Grid.RowDefinitions>
59             <TextBlock x:Name="txtItemTitle" HorizontalAlignment="Center"/>
60             <WebView x:Name="webViewContent" Grid.Row="1"/>
61         </Grid>
62     </Grid>
63 </Page>


后臺代碼如下:

C#

  1 using System;
  2 using System.Collections.Generic;
  3 using System.IO;
  4 using System.Linq;
  5 using System.Threading.Tasks;
  6 using Windows.Foundation;
  7 using Windows.Foundation.Collections;
  8 using Windows.Storage;
  9 using Windows.UI.Xaml;
 10 using Windows.UI.Xaml.Controls;
 11 using Windows.UI.Xaml.Controls.Primitives;
 12 using Windows.UI.Xaml.Data;
 13 using Windows.UI.Xaml.Input;
 14 using Windows.UI.Xaml.Media;
 15 using Windows.UI.Xaml.Navigation;
 16 using Windows.Web.Syndication;
 17 
 18 namespace Win8RssReader
 19 {
 20     public sealed partial class MainPage : Page
 21     {
 22         SyndicationClient syndicationClient;
 23         SyndicationFeed currentFeed;
 24 
 25         /// <summary>
 26         /// WebView在打開target="_blank"的超鏈接時會打開電腦上的瀏覽器,為了避免這種情況,這段js可通過更改DOM,使所有超鏈接的target="_self"。
 27         /// </summary>
 28         string MyJs { get; set; }
 29 
 30         public MainPage()
 31         {
 32             this.InitializeComponent();
 33         }
 34 
 35         async protected override void OnNavigatedTo(NavigationEventArgs e)
 36         {
 37             MyJs = await GetMyJs();
 38         }
 39 
 40         private async Task<string> GetMyJs()
 41         {
 42             StorageFile jsFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///js.txt"));
 43             string jsText = await FileIO.ReadTextAsync(jsFile);
 44             return jsText;
 45         }
 46 
 47         private async void btnGetFeed_Click(object sender, RoutedEventArgs e)
 48         {
 49             string feedUriString = txtFeedUri.Text;
 50             await GetFeedAsync(feedUriString);
 51             DisplayFeed();
 52         }
 53 
 54         private async Task GetFeedAsync(string feedUriString)
 55         {
 56             Uri uri;
 57             if (!Uri.TryCreate(feedUriString.Trim(), UriKind.Absolute, out uri))
 58             {
 59                 txtMsg.Text = "url錯誤";
 60                 return;
 61             }
 62             if (syndicationClient == null)
 63             {
 64                 syndicationClient = new SyndicationClient();
 65             }
 66             syndicationClient.BypassCacheOnRetrieve = true;
 67             syndicationClient.SetRequestHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
 68             txtMsg.Text = "開始下載...";
 69             try
 70             {
 71                 currentFeed = await syndicationClient.RetrieveFeedAsync(uri);
 72                 txtMsg.Text = "下載完成";
 73             }
 74             catch (Exception ex)
 75             {
 76                 txtMsg.Text = ex.Message;
 77             }
 78         }
 79 
 80         private void DisplayFeed()
 81         {
 82             if (currentFeed != null)
 83             {
 84                 ISyndicationText title = currentFeed.Title;
 85                 txtFeedTitle.Text = title != null ? title.Text : "(沒有標題)";
 86                 txtCount.Text = currentFeed.Items.Count.ToString();
 87                 listTitle.ItemsSource = currentFeed.Items;
 88                 listTitle.SelectedIndex = 0;//選中第0條,觸發(fā)SelectionChanged事件。
 89             }
 90         }
 91 
 92         private void listTitle_SelectionChanged(object sender, SelectionChangedEventArgs e)
 93         {
 94             var item = (SyndicationItem)listTitle.SelectedValue;
 95             DisplayCurrentItem(item);
 96         }
 97 
 98         private void DisplayCurrentItem(SyndicationItem item)
 99         {
100             if (item != null)
101             {
102                 txtItemTitle.Text = item.Title != null ? item.Title.Text : "(沒有標題)";
103                 string content = "(沒有內(nèi)容)";
104                 if (item.Content != null)
105                 {
106                     content = item.Content.Text;
107                 }
108                 else if (item.Summary != null)
109                 {
110                     content = item.Summary.Text;
111                 }
112                 content += MyJs;
113                 webViewContent.NavigateToString(content);
114             }
115         }
116     }
117 }


引用文件js.txt中的內(nèi)容如下:

<script type="text/javascript">
//WebView在打開target="_blank"的超鏈接時會打開電腦上的瀏覽器,為了避免這種情況,這段js可通過更改DOM,使所有超鏈接的target="_self"。
    var links = document.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
        links[i].target = "_self";
    }
</script>


題外話:

感覺現(xiàn)在做Windows Store App開發(fā)的很少哦,真心希望能和感興趣的朋友們交流交流。

    屏幕錄像
    (71)屏幕錄像
    西西軟件園提供了最新最全的屏幕錄像工具,其中體驗最好的就是屏幕錄像專家了,可以輕松地將屏幕上的軟件操作過程等錄制成FLASH動畫、AVI動畫或者自播放的EXE動畫.軟件采用先錄制,再生成的方式或者直接錄制的方式錄制屏幕錄像,使用戶對制作過程更加容易控制。本軟件使用簡單,功能強大,是制作各種屏幕錄像的首選軟件。...更多>>
    • 屏幕錄像(HyperCam)v3.0.912.18 中

      08-03 / 8.1M

      推薦理由:HyperCam是一套專門用來捕捉您的操作畫面的程序,包括鼠標的移動軌跡與音效,然后將它保存為標準的AVI視頻文
    • 騰訊屏幕錄像專家v1.0 綠色版

      07-29 / 791KB

      推薦理由:騰訊屏幕錄像專家是一款由網(wǎng)友自己制作的屏幕錄像軟件。軟件完全綠色免費,無毒無廣告,界面簡潔清晰,功能
    • frapsv3.5.99 漢化版

      10-16 / 2.5M

      推薦理由:Fraps是一個可以使用DirectX或OpenGL圖形技術(shù)在游戲中錄像的應(yīng)用程序,可以執(zhí)行許多任務(wù)。fraps錄制的視頻是
    • 小奇狗屏幕錄像機v1.0 綠色版

      06-04 / 2.2M

      推薦理由:小奇狗屏幕錄像機是一個可以把屏幕錄制成視頻的軟件。 可以制作視頻動畫,視頻演示,視頻教程等用途廣泛。
    • 超級屏幕錄像(Zeallsoft Super Scr

      04-28 / 2.9M

      推薦理由:Zeallsoft Super Screen Recorder 是一款小巧的屏幕錄像工具,可以很方便的錄像您的桌面,更多軟件技巧大家
    • 屏幕錄像機(321Soft Screen Video

      01-15 / 293KB

      推薦理由:最近一朋友想為公司員工制作幾個軟件使用教程,想要截圖并且需要錄像,可是試了一圈網(wǎng)上下載的一些屏幕錄制

    相關(guān)評論

    閱讀本文后您有什么感想? 已有人給出評價!

    • 8 喜歡喜歡
    • 3 頂
    • 1 難過難過
    • 5 囧
    • 3 圍觀圍觀
    • 2 無聊無聊

    熱門評論

    最新評論

    發(fā)表評論 查看所有評論(0)

    昵稱:
    表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
    字數(shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)