.NEt专家博客!
【李会军】一步一步学Silverlight 2系列(18):综合实例之RSS阅读器
概述
Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, Ironpython,对JSON、Web Service、WCF以及Sockets的支持等一系列新的特性。《一步一步学Silverlight 2系列》文章将从Silverlight 2基础知识、数据与通信、自定义控件、动画、图形图像等几个方面带您快速进入Silverlight 2开发
本文将综合前面十七篇讲过的界面布局、样式、控件模板、数据绑定、网络通信等几个方面,来开发一个综合实例——简易RSS阅读器。
界面布局
我们最终完成的RSS阅读器界面如下:
F"H#j jj,_C
n)Xr0
ITPUB个人空间A2yGpDY"wX@:Ay
定义一个三行两列的Grid,分别放置顶部信息、分割线和下面的内容区:
<Grid.RowDefinitions>ITPUB个人空间N N*z`\%S
<RowDefinitionHeight="50"></RowDefinition>
@ gq LmNlr6p0<RowDefinitionHeight="20"></RowDefinition>ITPUB个人空间0|(z E@^8xVk3w
<RowDefinitionHeight="*"></RowDefinition>
~ `o7|(o+B:\ | s0</Grid.RowDefinitions>
1pc)nN4g0<Grid.ColumnDefinitions>
,U!d%`*x0E N0<ColumnDefinitionWidth="240"></ColumnDefinition>ITPUB个人空间X|h,H%Q.N1`V3`e,j
<ColumnDefinitionWidth="*"></ColumnDefinition>ITPUB个人空间3a"Q9A S\:u
</Grid.ColumnDefinitions>
设计顶部输入区域,对Grid第一行做合并,并且放置一个StackPanel:
<StackPanelx:Name="Header"Orientation="Horizontal"ITPUB个人空间d0ApB.O Nh
Grid.Row="0"Grid.Column="0"Grid.ColumnSpan="2">
K2o+MA.TJ0<ImageSource="Rss.png"Width="32"Height="32"Margin="10 0 10 0"></Image>ITPUB个人空间t ~{FDQ~t@
<BorderStyle="{StaticResourcetitleBorder}">ITPUB个人空间0?:v[,@/D
<TextBlockText="基于Silverlight的RSS阅读器"Foreground="#FFFFFF"ITPUB个人空间Ag"a*J+I^f(Z
VerticalAlignment="Center"Margin="12 0 0 0"></TextBlock>
Q`/V6a.L K)p'S0</Border>ITPUB个人空间#D*CdX0\ SM
<WatermarkedTextBoxx:Name="feedAddress"Width="300"Height="35"ITPUB个人空间5d&bt"M8H\'S j\
FontSize="16"Margin="10 0 10 0">ITPUB个人空间5?,`IE^-{q{
<WatermarkedTextBox.Watermark>ITPUB个人空间#p!cpg0t'Q;oU
<TextBlockText="请输入有效的RSS地址"VerticalAlignment="Center"ITPUB个人空间1P/L;W*M ibG
Foreground="#FBA430"FontSize="16"></TextBlock>ITPUB个人空间Tq$q7f|0_"A
</WatermarkedTextBox.Watermark>
4l4Gt2k3nI0</WatermarkedTextBox>
;X2pV HN0<Buttonx:Name="displayButton"Style="{StaticResourcebutton}"
2RSY)p)wS G0Content="显 示"Click="displayButton_Click"></Button>ITPUB个人空间KOOD(c
<Buttonx:Name="fullScreenButton"Style="{StaticResourcebutton}"ITPUB个人空间Cx.dv,B9|zss
Content="全 屏"Click="fullScreenButton_Click"></Button>
3xY(OG0G0m?Y0</StackPanel>
鉴于两个按钮的风格一致,在App.xaml中定义一个button样式:
<Style.x:Key="button"TargetType="Button">ITPUB个人空间n0MQ-i"I
<SetterProperty="Width"Value="100"></Setter>
NqV1f,Iu/{)Q0<SetterProperty="Height"Value="35"></Setter>
4z1Hm q4Fqv0<SetterProperty="Background"Value="#FBA430"></Setter>ITPUB个人空间n7[,e{[!V
<SetterProperty="Foreground"Value="#FBA430"></Setter>ITPUB个人空间 mk dy8\a"P0S.T B
<SetterProperty="FontSize"Value="16"></Setter>ITPUB个人空间;~1^2d?0T(ua"f+L
</Style>ITPUB个人空间 m"x(C*?S
<Style.x:Key="titleBorder"TargetType="Border">ITPUB个人空间GJ Gfz2K8P
<SetterProperty="CornerRadius"Value="10"></Setter>
1`0pWA#Nwd-w0<SetterProperty="Width"Value="220"></Setter>
D6]{~)aK5z0<SetterProperty="Height"Value="40"></Setter>ITPUB个人空间!m(nRj2vfi
<SetterProperty="Background">ITPUB个人空间 X H%}xH2vZ
<Setter.Value>
_P%|+s5u+om0<LinearGradientBrushStartPoint="0,0">
I~y5Q.b_Q T:L0<GradientStopColor="#FBA430"Offset="0.0" />
y+ipL!t]e"`3L lU%R0<GradientStopColor="#FEF4E7"Offset="0.5" />
~gG[&i2`9B|7l0<GradientStopColor="#FBA430"Offset="1.0" />