概要:
Sl已经学习有一段时间了,但总是怀疑已学的东西到底能不能做出一些东西。今天照着例子动手写一下,验证一下。
内容:
首先还是xaml的布局。都是一些控件的使用,但是让我来做肯定丑的自己都看不下去。以前最头疼的就是做页面,是没这方面细胞,还是根本就没好好练过?
MainPage.xaml:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="500" d:DesignWidth="800"> Grid.Row="0" Grid.Column="0"Grid.ColumnSpan="2"> VerticalAlignment="Center" Margin="12 0 00"> FontSize="16"Margin="10 0 10 0"> Margin="10 5 5 10"SelectionChanged="PostsList_SelectionChanged"> TextWrapping="Wrap" Width="200"/> Width="540"Height="40"> VerticalAlignment="Center" Foreground="Red"/> Width="540"Height="300"> Width="540"Height="40"> Foreground="Red" VerticalAlignment="Center"/> Foreground="Red" VerticalAlignment="Center"/> 样式部分代码,AppPage.xaml: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SLDemo18RssRead.App" > 代码: /// /// 显示列表 /// /// /// private void displayButton_Click(object sender, RoutedEventArgs e) { Uri uri = new Uri(feedAddress.Text); WebRequest request = (WebRequest)WebRequest.Create(uri); request.BeginGetResponse(new AsyncCallback(responseReady), request); } void responseReady(IAsyncResult asyncResult) { WebRequest request = (WebRequest)asyncResult.AsyncState; WebResponse response = (WebResponse)request.EndGetResponse(asyncResult); XmlReader reader = XmlReader.Create(response.GetResponseStream()); SyndicationFeed feed = SyndicationFeed.Load(reader); PostsList.ItemsSource = feed.Items; } /// /// 全屏显示 /// /// /// private void fullScreenButton_Click(object sender, RoutedEventArgs e) { Content contentObject = Application.Current.Host.Content; contentObject.IsFullScreen = !contentObject.IsFullScreen; } /// /// 查看详细信息 /// /// /// private void PostsList_SelectionChanged(object sender,SelectionChangedEventArgs e) { SyndicationItem item = PostsList.SelectedItem as SyndicationItem; Detail.DataContext = item; } 注: 代码所需的引用: System.Xml.LinQ; System.ServiceModel; System.ServiceModel.Syndication; 引入的命名空间总共有: using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Xml; using System.Xml.Linq; using System.Windows.Interop; using System.ServiceModel.Syndication; 总结: 做这个例子可能遇到的困难首先是引入命名空间问题,在什么情况下需要引入什么命名空间,这个我只是照着例子试试看。我想这个也没什么取巧的方法,只能靠积累,总结。 还有一个可能只是对我来说是个困难,就是如何才能有一个漂亮的布局?以前做web我主要做逻辑,实体等部分,页面部分有别的人来做的。但这个SL主要还是用来显示的,所以我总觉得SL在我手上是被糟蹋的感觉。。。 转载于:https://www.cnblogs.com/yaoge/archive/2010/09/09/1822606.html