<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>『听风且吟』技术版 &#187; Silverlight/WPF</title>
	<atom:link href="http://coding.windstyle.cn/category/silverlightwpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://coding.windstyle.cn</link>
	<description>Windie Chai&#039;s technique blog</description>
	<lastBuildDate>Tue, 07 Sep 2010 06:10:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>简单的Silverlight音乐播放器Widget</title>
		<link>http://coding.windstyle.cn/2008/06/26/simple-silverlight-music-player-widget/</link>
		<comments>http://coding.windstyle.cn/2008/06/26/simple-silverlight-music-player-widget/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 17:33:00 +0000</pubDate>
		<dc:creator>windie</dc:creator>
				<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[音乐播放器]]></category>

		<guid isPermaLink="false">http://1230091</guid>
		<description><![CDATA[上周尝试了一下发布不久的Silverlight 2 beta2，设计了这么一个简单的播放器widget。它支持循环播放，支持自动播放，支持封面图片，支持暂停（鼠标移动到封面上就会淡入按钮）。 本来是想设计的稍微酷一点的，发现Silverlight2的矩阵变形能力还是相当弱的，其实现的功能也就是平移、平行四边形化和旋转，如果再支持梯形化就好了。 发现Silverlight 2 beta2相对beta1的一些小变化： 1.字体优化，beta1总算支持了中文显示，但却显示的非常别扭。 一句话会出现两种字体，貌似规律是这样的，如果某个汉字的繁简体一样的话，那么这个汉字在Silverlight中显示为黑体，否则为宋体。 其实微软的网站上早就有这样的先例，譬如下图： 2.Image不再像之前那样使用依赖属性赋一个Uri就可以了，而是变成了下面的样子：&#160; BitmapImage bmp = new BitmapImage(); bmp.UriSource = new Uri(cover); this.img_Cover.Source = bmp; 3.另外，之前基于beta1制作的饭否widget无法编译通过了，在异步调用的方法中，似乎无法直接操作控件的属性了，不知何解。 OK。如果你也想在blog上添加这个widget，那么编辑主题，在相应的位置加入以下代码： &#60;a href=&#34;http://go.microsoft.com/fwlink/?LinkID=115261&#34;&#62; &#60;img src=&#34;http://go.microsoft.com/fwlink/?LinkId=108181&#34; alt=&#34;Get Microsoft Silverlight&#34; style=&#34;border-style: none&#34; /&#62; &#60;/a&#62; 稍微介绍一下InitParams的配置就可以了，它包含了音乐url（music）、封面url（cover）、标题（title）、自动播放（auto）和循环（loop），各个参数之间用半角逗号分割即可。 点击下载示例源码 Related posts Silverlight 2 打造饭否Show (31)]]></description>
			<content:encoded><![CDATA[<p>上周尝试了一下发布不久的Silverlight 2 beta2，设计了这么一个简单的播放器widget。它支持循环播放，支持自动播放，支持封面图片，支持暂停（鼠标移动到封面上就会淡入按钮）。</p>
<p>本来是想设计的稍微酷一点的，发现<a title="TerryLee的Silverlight系列文章" href="http://www.cnblogs.com/Terrylee/archive/2008/03/19/Silverlight2-step-by-step-part29-Transform-part2.html" target="_blank">Silverlight2的矩阵变形能力</a>还是相当弱的，其实现的功能也就是平移、平行四边形化和旋转，如果再支持梯形化就好了。 <span id="more-697"></span></p>
<p><img src="http://coding.windstyle.cn/files/cnblogs/draft.jpg" border="0" alt="" /><img src="http://coding.windstyle.cn/files/cnblogs/windstyleplayer.jpg" border="0" alt="" /></p>
<p>发现Silverlight 2 beta2相对beta1的一些小变化：</p>
<p>1.字体优化，beta1总算支持了中文显示，但却显示的非常别扭。</p>
<p>一句话会出现两种字体，貌似规律是这样的，如果某个汉字的繁简体一样的话，那么这个汉字在Silverlight中显示为黑体，否则为宋体。</p>
<p>其实微软的网站上早就有这样的先例，譬如下图：</p>
<p><img src="http://coding.windstyle.cn/files/cnblogs/fontonmssite.png" border="0" alt="" /></p>
<p>2.Image不再像之前那样使用依赖属性赋一个Uri就可以了，而是变成了下面的样子：&nbsp;</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">BitmapImage bmp = new BitmapImage();<br />
bmp.UriSource = new Uri(cover);<br />
this.img_Cover.Source = bmp;</div></div>
<p>3.另外，之前<a href="http://coding.windstyle.cn/2008/04/29/build-fanfou-show-using-silverlight-2/">基于beta1制作的饭否widget</a>无法编译通过了，在异步调用的方法中，似乎无法直接操作控件的属性了，不知何解。</p>
<p>OK。如果你也想在blog上添加这个widget，那么编辑主题，在相应的位置加入以下代码：</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;a href=&quot;http://go.microsoft.com/fwlink/?LinkID=115261&quot;&gt;<br />
&lt;img src=&quot;http://go.microsoft.com/fwlink/?LinkId=108181&quot; alt=&quot;Get Microsoft Silverlight&quot; style=&quot;border-style: none&quot; /&gt;<br />
&lt;/a&gt;</div></div>
<p>稍微介绍一下InitParams的配置就可以了，它包含了音乐url（music）、封面url（cover）、标题（title）、自动播放（auto）和循环（loop），各个参数之间用半角逗号分割即可。</p>
<p><a href="http://coding.windstyle.cn/files/2008/06/WindStylePlayer.zip">点击下载示例源码</a></p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://coding.windstyle.cn/2008/04/29/build-fanfou-show-using-silverlight-2/" title="Silverlight 2 打造饭否Show (2008-04-29)">Silverlight 2 打造饭否Show</a> (31)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://coding.windstyle.cn/2008/06/26/simple-silverlight-music-player-widget/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Silverlight 2 打造饭否Show</title>
		<link>http://coding.windstyle.cn/2008/04/29/build-fanfou-show-using-silverlight-2/</link>
		<comments>http://coding.windstyle.cn/2008/04/29/build-fanfou-show-using-silverlight-2/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 17:38:00 +0000</pubDate>
		<dc:creator>windie</dc:creator>
				<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[跨域]]></category>
		<category><![CDATA[饭否]]></category>

		<guid isPermaLink="false">http://1175401</guid>
		<description><![CDATA[在Silverlight 1.1的时候，我就像用Silverlight设计一个饭否Show，无奈1.1时代貌似只能通过Web Services来获取跨域的数据，我认为这是一种别扭的开发方式，再加上1.1对中文并不友好，所以就改用Flash实现了这个饭否Show。 Silverlight 2终于解决了上述的两个问题，支持跨域获取数据，支持中文显示，于是我迫不及待的尝试着开发了一个饭否Show（在Silverlight 2 beta SDK 发布的几日后开始开发，开发完成后便忘记了，-___-&#124;&#124;&#124;），下面来简要的分享一下开发过程，也望各位Silverlight前辈不吝指教。 UI UI的界面如下图所示： UI采用Blend 2.5和Design设计。 如果设计简单的Silverlight界面，那么Blend足矣，但稍复杂的，比如上图中的波浪渐变效果，Blend就无能为力了，而这正是Design的拿手本领。 Design的使用方法就不介绍了，设计完毕后，导出为Silverlight画布，然后我们copy需要的XAML节点即可。 具体的XAML内容就不在此展示了，文末我提供了本文的代码下载，有兴趣的朋友可以下载查看。 饭否API 从上图来分析，我们只用到了饭否中的两部分信息：我的信息和我的消息。 在饭否API中，获取这两部分数据的方法如下： 获取用户信息： http://api.fanfou.com/users/show/用户ID.xml 获取用户消息： http://api.fanfou.com/statuses/user_timeline/用户ID.rss 那么根据饭否提供的API，我编写了下面两个类： using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.IO; using System.Linq; using System.Xml; using System.Xml.Linq; using System.Collections.Generic; namespace SilverlightFanShow { [...]]]></description>
			<content:encoded><![CDATA[<p>在Silverlight 1.1的时候，我就像用Silverlight设计一个饭否Show，无奈1.1时代貌似只能通过Web Services来获取跨域的数据，我认为这是一种别扭的开发方式，再加上1.1对中文并不友好，所以就改用Flash实现了这个饭否Show。<br />
Silverlight 2终于解决了上述的两个问题，支持跨域获取数据，支持中文显示，于是我迫不及待的尝试着开发了一个饭否Show（在Silverlight 2 beta SDK 发布的几日后开始开发，开发完成后便忘记了，-___-|||），下面来简要的分享一下开发过程，也望各位Silverlight前辈不吝指教。<span id="more-699"></span></p>
<h2>UI</h2>
<p>UI的界面如下图所示：<br />
<img src="http://images.cnblogs.com/cnblogs_com/xiaoshatian/85614/SilverlightFanfouShow.png" border="0" alt="" /><br />
UI采用Blend 2.5和Design设计。<br />
如果设计简单的Silverlight界面，那么Blend足矣，但稍复杂的，比如上图中的波浪渐变效果，Blend就无能为力了，而这正是Design的拿手本领。<br />
Design的使用方法就不介绍了，设计完毕后，导出为Silverlight画布，然后我们copy需要的XAML节点即可。<br />
具体的XAML内容就不在此展示了，文末我提供了本文的代码下载，有兴趣的朋友可以下载查看。</p>
<h2>饭否API</h2>
<p>从上图来分析，我们只用到了饭否中的两部分信息：我的信息和我的消息。<br />
在<a href="http://help.fanfou.com/api.html" target="_blank">饭否API</a>中，获取这两部分数据的方法如下：<br />
获取用户信息：<br />
http://api.fanfou.com/users/show/<span style="color: #000000">用户ID</span>.xml<br />
获取用户消息：<br />
http://api.fanfou.com/statuses/user_timeline/<span style="color: #000000">用户ID</span>.rss<br />
那么根据饭否提供的API，我编写了下面两个类：</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">using System;<br />
using System.Windows;<br />
using System.Windows.Controls;<br />
using System.Windows.Documents;<br />
using System.Windows.Ink;<br />
using System.Windows.Input;<br />
using System.Windows.Media;<br />
using System.Windows.Media.Animation;<br />
using System.Windows.Shapes;<br />
using System.IO;<br />
using System.Linq;<br />
using System.Xml;<br />
using System.Xml.Linq;<br />
using System.Collections.Generic;<br />
<br />
namespace SilverlightFanShow<br />
{<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 饭否用户<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public class FanfouUser<br />
&nbsp;{<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 用户头像的URL<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public Uri ImageURL{get;set;}<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 用户的显示名称<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public string Name{get;set;}<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 用户的饭否链接地址<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public Uri URL{get;set;}<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 从Stream加载饭否用户实例<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;/// <br />
&nbsp;/// <br />
&nbsp;public static FanfouUser Load(Stream stream)<br />
&nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FanfouUser user = new FanfouUser();<br />
<br />
&nbsp;try<br />
&nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XmlReader reader = XmlReader.Create(stream);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XElement doc = XElement.Load(reader);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.ImageURL = new Uri(doc.Descendants(&quot;profile_image_url&quot;).FirstOrDefault().Value);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.Name = doc.Descendants(&quot;name&quot;).FirstOrDefault().Value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user.URL = new Uri(doc.Descendants(&quot;url&quot;).FirstOrDefault().Value);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp;catch { }<br />
<br />
&nbsp;return user;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 默认构造函数<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public FanfouUser()<br />
&nbsp;{<br />
&nbsp;this.ImageURL = new Uri(&quot;http://avatar.fanfou.com/s0/00/4q/py.jpg?1183096447&quot;);<br />
&nbsp;this.Name = &quot;Windie&quot;;<br />
&nbsp;this.URL = new Uri(&quot;http://fanfou.com/笑煞天&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 饭否消息<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public class FanfouMessage<br />
&nbsp;{<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 饭否消息的GUID（注：并不是.NET里的GUID）<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public string GUID { get; set; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 饭否消息本体<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public string Message { get; set; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 饭否消息的发布时间<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public DateTime Time { get; set; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 从Stream加载饭否消息列表<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;/// <br />
&nbsp;/// <br />
&nbsp;public static List Load(Stream stream)<br />
&nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List msgList = new List();<br />
<br />
&nbsp;try<br />
&nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XmlReader reader = XmlReader.Create(stream);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XElement doc = XElement.Load(reader);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IEnumerable msgs = from item in doc.Descendants(&quot;item&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;select item;<br />
&nbsp;foreach (XElement item in msgs)<br />
&nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FanfouMessage msg = new FanfouMessage();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msg.GUID = item.Descendants(&quot;guid&quot;).FirstOrDefault().Value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msg.Message = item.Descendants(&quot;title&quot;).FirstOrDefault().Value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msg.Time = DateTime.Parse(item.Descendants(&quot;pubDate&quot;).FirstOrDefault().Value);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msgList.Add(msg);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }catch{ }<br />
<br />
&nbsp;return msgList;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 默认构造函数<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;public FanfouMessage()<br />
&nbsp;{<br />
&nbsp;this.GUID = Guid.NewGuid().ToString();<br />
&nbsp;this.Message = &quot;欢迎使用Windie Chai设计的Silverlight饭否Show。&quot;;<br />
&nbsp;this.Time = DateTime.Now;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
}</div></div>
<h2>传入参数</h2>
<p>其实我设计这个饭否Show并不是只为了给我一个人使用，那么如何让每位朋友都可以把它变成自己的饭否Show呢？<br />
那么必然要使Silverlight能够接受参数。<br />
在做Flash开发时，可以在HTML中通过Object的“FlashVars”参数来向Flash传递参数列表，在Silverlight中我们同样可以这样做。<br />
通过给“<span style="font-family: Verdana">InitParams”参数赋值，我们就可以向Silverlight传递参数了。<br />
</span>给“<span style="font-family: Verdana">InitParams”参数赋值</span>的方法如下：</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;a href=&quot;http://go.microsoft.com/fwlink/?LinkID=108182&quot;&gt;<br />
&lt;img src=&quot;http://go.microsoft.com/fwlink/?LinkId=108181&quot; alt=&quot;Get Microsoft Silverlight&quot; style=&quot;border-style: none&quot; /&gt;<br />
&lt;/a&gt;</div></div>
<p>仅仅把ID参数传入到Silverlight中是不够的，我们还需要在Silverlight中接收这个参数，并做进一步处理。<br />
我们打开Silverlight项目中的App.xaml，为其Application_Startup事件添加如下代码：</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">private void Application_Startup(object sender, StartupEventArgs e)<br />
{<br />
&nbsp;string id = &quot;笑煞天&quot;;<br />
&nbsp;if(e.InitParams.Keys.Contains(&quot;ID&quot;))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id = e.InitParams[&quot;ID&quot;];<br />
&nbsp;this.RootVisual = new Page(id);<br />
}</div></div>
<p>要注意的是Page默认并没有带有一个String参数的构造函数，所以我们接下来还需要为Page类添加这一构造函数重载。</p>
<h2>Page.xaml.cs</h2>
<p>最后，我们开始编写最关键的代码。我将在Page.xaml.cs中添加方法或事件来调用饭否API、获取用户的信息和消息列表、实现上一条下一条的跳转等。<br />
具体的代码并不难以理解，不再详细解释，大家看注释便好：</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:500px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Windows;<br />
using System.Windows.Controls;<br />
using System.Windows.Documents;<br />
using System.Windows.Input;<br />
using System.Windows.Media;<br />
using System.Windows.Media.Animation;<br />
using System.Windows.Shapes;<br />
using System.Net;<br />
using System.IO;<br />
using System.Xml;<br />
using System.Xml.Linq;<br />
using System.Threading;<br />
using System.Windows.Browser;<br />
<br />
namespace SilverlightFanShow<br />
{<br />
&nbsp;public partial class Page : UserControl<br />
&nbsp;{<br />
&nbsp;//饭否用户ID<br />
&nbsp;private string userID;<br />
&nbsp;//饭否用户<br />
&nbsp;private FanfouUser user;<br />
<br />
&nbsp;//当前消息<br />
&nbsp;private FanfouMessage currentMessage;<br />
<br />
&nbsp;//消息列表<br />
&nbsp;private List messageList;<br />
<br />
&nbsp;public Page(string id)<br />
&nbsp;{<br />
&nbsp;this.userID = id;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InitializeComponent();<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 布局加载事件<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;/// <br />
&nbsp;/// <br />
&nbsp;private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)<br />
&nbsp;{<br />
&nbsp;//加载用户信息<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Uri userUrl = new Uri(&quot;http://api.fanfou.com/users/show/&quot;<br />
&nbsp;+ this.userID<br />
&nbsp;+ &quot;.xml&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebRequest userRequest = WebRequest.Create(userUrl);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; userRequest.BeginGetResponse(new AsyncCallback(GetUserInfo), userRequest);<br />
<br />
&nbsp;//加载用户消息<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Uri msgUrl = new Uri(&quot;http://api.fanfou.com/statuses/user_timeline/&quot;<br />
&nbsp;+ this.userID<br />
&nbsp;+ &quot;.rss&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebRequest msgRequest = WebRequest.Create(msgUrl);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msgRequest.BeginGetResponse(new AsyncCallback(GetMessages), msgRequest);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 获取用户信息<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;/// <br />
&nbsp;void GetUserInfo(IAsyncResult asyncResult)<br />
&nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebRequest request = asyncResult.AsyncState as WebRequest;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebResponse response= request.EndGetResponse(asyncResult);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stream stream = response.GetResponseStream();<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user = FanfouUser.Load(stream);<br />
<br />
&nbsp;//反映到UI<br />
&nbsp;this.pic.SetValue(Image.SourceProperty, user.ImageURL);<br />
&nbsp;this.userName.Text = user.Name;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 获取用户消息<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;/// <br />
&nbsp;void GetMessages(IAsyncResult asyncResult)<br />
&nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebRequest request = asyncResult.AsyncState as WebRequest;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WebResponse response = request.EndGetResponse(asyncResult);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stream stream = response.GetResponseStream();<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageList = FanfouMessage.Load(stream);<br />
<br />
&nbsp;//反映到UI<br />
&nbsp;if(messageList.Count &amp;gt; 1)<br />
&nbsp;this.SetMessage(messageList[0]);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 设置当前消息<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;/// <br />
&nbsp;private void SetMessage(FanfouMessage message)<br />
&nbsp;{<br />
&nbsp;//去掉消息正文前边的用户名<br />
&nbsp;string msg = message.Message.Substring(message.Message.IndexOf('：') + 1);<br />
&nbsp;//如果消息正文过长，截短之<br />
&nbsp;if (msg.Length &amp;gt; 50)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msg = msg.Substring(0, 50) + &quot;&quot;;<br />
&nbsp;this.txt.Text = msg;<br />
&nbsp;this.time.Text = message.Time.ToShortDateString();<br />
&nbsp;this.currentMessage = message;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 下一条消息按钮按下事件<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;/// <br />
&nbsp;/// <br />
&nbsp;private void btnNext_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)<br />
&nbsp;{<br />
&nbsp;int msgIndex = messageList.IndexOf(currentMessage);<br />
&nbsp;if (msgIndex + 1 &nbsp;0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetMessage(messageList[0]);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 下一条消息按钮按下事件<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;/// <br />
&nbsp;/// <br />
&nbsp;private void btnPrev_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)<br />
&nbsp;{<br />
&nbsp;int msgIndex = messageList.IndexOf(currentMessage);<br />
&nbsp;if (msgIndex &amp;gt; 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetMessage(messageList[msgIndex - 1]);<br />
&nbsp;else if (messageList.Count &amp;gt; 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetMessage(messageList[messageList.Count - 1]);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp;/**//// &lt;summary&gt;<br />
&nbsp;/// 头像点击事件<br />
&nbsp;/// &lt;/summary&gt;<br />
&nbsp;/// <br />
&nbsp;/// <br />
&nbsp;private void goToFanfou(object sender, MouseButtonEventArgs e)<br />
&nbsp;{<br />
&nbsp;//打开用户的饭否页面<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HtmlPage.Window.Navigate(this.user.URL, &quot;_blank&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
}</div></div>
<h2>预览</h2>
<p><a href="http://go.microsoft.com/fwlink/?LinkID=108182"></p>
<p><img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"><br />
</a><br />
如果你也想要在你的blog中添加这个Widget，那么，Copy上面的HTML代码，修改ID就可以了。</p>
<h2>源码下载</h2>
<p><a href="http://coding.windstyle.cn/files/2008/04/silverlightfanshow.zip">点击下载源码包（包括Visual Studio Solution和Expression Design文件）</a></p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://coding.windstyle.cn/2009/11/22/make-your-code-more-comfortable-2-select-the-appropriate-font/" title="让代码看起来更舒服（2）：选择适合的字体 (2009-11-22)">让代码看起来更舒服（2）：选择适合的字体</a> (0)</li>
	<li><a href="http://coding.windstyle.cn/2008/06/26/simple-silverlight-music-player-widget/" title="简单的Silverlight音乐播放器Widget (2008-06-26)">简单的Silverlight音乐播放器Widget</a> (15)</li>
	<li><a href="http://coding.windstyle.cn/2007/06/08/ajax-net-1-0-fix-cross-domain-acess-error/" title="Ajax.net 1.0跨域访问错误的解决方法 (2007-06-08)">Ajax.net 1.0跨域访问错误的解决方法</a> (0)</li>
	<li><a href="http://coding.windstyle.cn/2007/08/05/create-sharepoint-workflow-using-visual-studio-2008-beta2/" title="使用VISUAL STUDIO 2008 BETA2 创建 SHAREPOINT 工作流 (2007-08-05)">使用VISUAL STUDIO 2008 BETA2 创建 SHAREPOINT 工作流</a> (13)</li>
	<li><a href="http://coding.windstyle.cn/2010/01/24/sharepoint-2010-codeless-workflow-overview-2/" title="泛谈SharePoint 2010无代码工作流 (2010-01-24)">泛谈SharePoint 2010无代码工作流</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://coding.windstyle.cn/2008/04/29/build-fanfou-show-using-silverlight-2/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
	</channel>
</rss>
