﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-木野狐(Neil Chen)</title><link>http://www.cnblogs.com/RChen/</link><description>Speak less, do more.</description><language>zh-cn</language><lastBuildDate>Fri, 25 Jul 2008 06:22:05 GMT</lastBuildDate><pubDate>Fri, 25 Jul 2008 06:22:05 GMT</pubDate><ttl>60</ttl><item><title>[Silverlight] 如何在 Worker thread 中更新 UI</title><link>http://www.cnblogs.com/RChen/archive/2008/07/25/1250948.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Thu, 24 Jul 2008 17:30:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/25/1250948.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1250948.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/25/1250948.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1250948.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1250948.html</trackback:ping><description><![CDATA[Silverlight 中调用服务全部采用异步方式，在调用 WCF 时似乎没有什么问题。<br>但是如果要用一个 WebRequest 对象去向某个页面 Post 一些内容，然后获得回应。<br>就会发现在 Worker thread 中将无法更新 UI.<br>在 Windows Forms 里，可以用 Control.Invoke. 但是 Silverlight 没有这个。<br><br>Silverlight 中有更好的办法。DependencyObject 类有一个属性 Dispatcher，可以通过它来更新相关 UI 对象。<br>比如可以这样写：<br><br>（假设是在上传一个文件后更新文件列表）<br><br><div class="cnblogs_code"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;UpdateFileList(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;newFileId)<br>{<br>&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;<img src="http://www.cnblogs.com/images/dot.gif"></span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">}<br></span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">delegate</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;UpdateFileListDelegate(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;newFileId);<br><br></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;Worker&nbsp;thread</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;ResponseReady(IAsyncResult&nbsp;asyncResult)<br>{<br>&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;<img src="http://www.cnblogs.com/images/dot.gif"><br>&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">&nbsp;更新文件列表</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;listFiles.Dispatcher.BeginInvoke(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;UpdateFileListDelegate(UpdateListFile),&nbsp;newFileId<br>&nbsp;&nbsp;&nbsp;);<br>}</span></div><br><br>注意这个 BeginInvoke 方法很先进. 他可以接受任何的 delegate，还能传递任意数目的参数过去。<br>这里传了一个简单的 newFileId.<br><br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1250948.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41298/" target="_blank">[新闻]SourceForge可正常访问</a>]]></description></item><item><title>Linq to sql 中如何进行 left join</title><link>http://www.cnblogs.com/RChen/archive/2008/07/24/1250736.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Thu, 24 Jul 2008 09:09:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/24/1250736.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1250736.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/24/1250736.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1250736.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1250736.html</trackback:ping><description><![CDATA[可以用 into 语法，配合 DefaultIfEmpty() 方法加载右侧表中的空值。<BR>例子：<BR><BR>
<DIV class=cnblogs_code><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><SPAN style="COLOR: rgb(0,0,0)">var&nbsp;query&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR>&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;r&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">in</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;db.Roles<BR>&nbsp;&nbsp;&nbsp;&nbsp;join&nbsp;sr&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">in</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;ss&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">in</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;db.StaffInRoles<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">where</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;ss.StaffId&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">==</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;staffId<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;ss<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on&nbsp;r.Id&nbsp;equals&nbsp;sr.RoleId<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT style="BACKGROUND-COLOR: #d3d3d3">into&nbsp;x</FONT><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;<FONT style="BACKGROUND-COLOR: #d3d3d3">from&nbsp;y&nbsp;</FONT></SPAN><SPAN style="COLOR: rgb(0,0,255)"><FONT style="BACKGROUND-COLOR: #d3d3d3">in</FONT></SPAN><SPAN style="COLOR: rgb(0,0,0)"><FONT style="BACKGROUND-COLOR: #d3d3d3">&nbsp;x.DefaultIfEmpty()<BR></FONT>&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;RoleInfo<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RoleId&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;r.Id,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RoleName&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;r.Name,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IsSet&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;y&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">!=</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">null</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR>&nbsp;&nbsp;&nbsp;&nbsp;};</SPAN></DIV><BR><BR>注意这里最后可以通过 y != null 来判断右值是否为空。<BR><BR>这个 Linq to sql 语句生成的对应 SQL 为：<BR><BR>
<DIV class=cnblogs_code><SPAN style="COLOR: #0000ff">exec</SPAN><SPAN style="COLOR: #000000">&nbsp;sp_executesql&nbsp;N</SPAN><SPAN style="COLOR: #ff0000">'</SPAN><SPAN style="COLOR: #ff0000">SELECT&nbsp;[t0].[Id]&nbsp;AS&nbsp;[RoleId],&nbsp;[t0].[Name]&nbsp;AS&nbsp;[RoleName],&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;(CASE&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHEN&nbsp;[t2].[test]&nbsp;IS&nbsp;NOT&nbsp;NULL&nbsp;THEN&nbsp;1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ELSE&nbsp;0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END)&nbsp;AS&nbsp;[IsSet]<BR>FROM&nbsp;[Role]&nbsp;AS&nbsp;[t0]<BR>LEFT&nbsp;OUTER&nbsp;JOIN&nbsp;(<BR>&nbsp;&nbsp;&nbsp;&nbsp;SELECT&nbsp;1&nbsp;AS&nbsp;[test],&nbsp;[t1].[StaffId],&nbsp;[t1].[RoleId]<BR>&nbsp;&nbsp;&nbsp;&nbsp;FROM&nbsp;[StaffInRole]&nbsp;AS&nbsp;[t1]<BR>&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;AS&nbsp;[t2]&nbsp;ON&nbsp;([t0].[Id]&nbsp;=&nbsp;[t2].[RoleId])&nbsp;AND&nbsp;([t2].[StaffId]&nbsp;=&nbsp;@p0)</SPAN><SPAN style="COLOR: #ff0000">'</SPAN><SPAN style="COLOR: #000000">,N</SPAN><SPAN style="COLOR: #ff0000">'</SPAN><SPAN style="COLOR: #ff0000">@p0&nbsp;int</SPAN><SPAN style="COLOR: #ff0000">'</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #008000">@p0</SPAN><SPAN style="COLOR: #808080">=</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #800000">1</SPAN></DIV><BR><BR>over.<img src ="http://www.cnblogs.com/RChen/aggbug/1250736.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41295/" target="_blank">[新闻]2008年7月25日IT博客精选</a>]]></description></item><item><title>Silverlight 2 beta 2 bug 解决办法 (持续更新中)</title><link>http://www.cnblogs.com/RChen/archive/2008/07/24/1250729.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Thu, 24 Jul 2008 09:03:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/24/1250729.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1250729.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/24/1250729.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1250729.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1250729.html</trackback:ping><description><![CDATA[1. ListBox 的 Item 里的 CheckBox 不能正确选中。<br><br>&nbsp;&nbsp; 该 bug 表现为需要先选中 ListItem,然后才能选中相应的 CheckBox.<br>&nbsp;&nbsp; <br>&nbsp;&nbsp; 临时解决办法：<br>&nbsp;&nbsp; 设置 CheckBox 的 ClickMode 属性为 Press.<br><br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1250729.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41295/" target="_blank">[新闻]2008年7月25日IT博客精选</a>]]></description></item><item><title>Silverlight + WCF 常见错误调试方法</title><link>http://www.cnblogs.com/RChen/archive/2008/07/23/1249780.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Wed, 23 Jul 2008 08:21:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/23/1249780.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1249780.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/23/1249780.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1249780.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1249780.html</trackback:ping><description><![CDATA[1、 404 Not Found<br><br>a. 检查服务器是否放了 ClientAccessPolicy.xml 文件。内容范例如下：<br><br><div class="cnblogs_code"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">&lt;?</span><span style="color: rgb(255, 0, 255);">xml&nbsp;version="1.0"&nbsp;encoding="utf-8"&nbsp;</span><span style="color: rgb(0, 0, 255);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">access-policy</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">cross-domain-access</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">policy</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">allow-from&nbsp;</span><span style="color: rgb(255, 0, 0);">http-request-headers</span><span style="color: rgb(0, 0, 255);">="*"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">domain&nbsp;</span><span style="color: rgb(255, 0, 0);">uri</span><span style="color: rgb(0, 0, 255);">="*"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">allow-from</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">grant-to</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">resource&nbsp;</span><span style="color: rgb(255, 0, 0);">path</span><span style="color: rgb(0, 0, 255);">="/"</span><span style="color: rgb(255, 0, 0);">&nbsp;include-subpaths</span><span style="color: rgb(0, 0, 255);">="true"</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">grant-to</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">policy</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">cross-domain-access</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">access-policy</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br></span></div><br>b. 还有可能因为其他原因造成，可以用 http 监听工具查看 response 的内容，看到异常信息。<br><br><br>2. 调用 WCF 时发现传参丢失，变成 null.<br><br>&nbsp; 原因：客户端代理不同步，更新一下服务引用即可。<br><br><br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1249780.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41292/" target="_blank">[新闻]微软称Windows 7开发很顺利 IE 8年底上市</a>]]></description></item><item><title>[Silverlight] 写了两个方便 DOM 查找的扩展方法</title><link>http://www.cnblogs.com/RChen/archive/2008/07/23/1249523.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Wed, 23 Jul 2008 06:09:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/23/1249523.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1249523.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/23/1249523.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1249523.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1249523.html</trackback:ping><description><![CDATA[Silverlight 中有所谓视觉树(Visual Tree)的概念，而 VisualTree 是一个运行时的概念，其实可以理解为一种 DOM.<br>其内容的来源可以是几个方面：<br><br>&nbsp;1.静态 XAML 文件中创建的。<br>&nbsp;2.用 XamlReadler.Load() 方法动态加载的 XAML 内容。<br>&nbsp;3.完全通过代码创建的控件。<br><br>在 XAML 中我们通过 x:Name 来标识一个元素，但是光靠 Name 不能解决全部的问题，特别对于一些动态的场景而言。<br>有时候我们还需要根据控件的类型或者其他条件来查找节点。<br>比如：<br>&nbsp;&nbsp;&nbsp; “<font color="#ff0000">给我找出当前这个控件在哪个 Tab 页（TabItem）中</font>”<br>&nbsp;&nbsp;&nbsp; “<font color="#ff0000">找出祖先控件中谁实现了 IDialogHost 接口（准备显示一个对话框加载当前用户控件的内容）</font>”<br>等等类似的需求。<br><br>于是就有了下面两个方法：<br><br><div class="cnblogs_code"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Collections.Generic;<br></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Windows;<br></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Windows.Media;<br><br></span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);">&nbsp;NeilChen.SilverlightExtensions<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;DomExtensions<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;summary&gt;</span><span style="color: rgb(0, 128, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;查找祖先节点<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;/summary&gt;</span><span style="color: rgb(0, 128, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;typeparam&nbsp;name="T"&gt;</span><span style="color: rgb(0, 128, 0);">目标节点的类型</span><span style="color: rgb(128, 128, 128);">&lt;/typeparam&gt;</span><span style="color: rgb(0, 128, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;param&nbsp;name="child"&gt;</span><span style="color: rgb(0, 128, 0);">起始节点</span><span style="color: rgb(128, 128, 128);">&lt;/param&gt;</span><span style="color: rgb(0, 128, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;returns&gt;&lt;/returns&gt;</span><span style="color: rgb(128, 128, 128);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">&nbsp;T&nbsp;FindAncestor</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">&nbsp;DependencyObject&nbsp;child)&nbsp;</span><span style="color: rgb(0, 0, 255);">where</span><span style="color: rgb(0, 0, 0);">&nbsp;T&nbsp;:&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;d&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;VisualTreeHelper.GetParent(child);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;(d&nbsp;</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">(d&nbsp;</span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);">&nbsp;T))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;VisualTreeHelper.GetParent(d);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;d&nbsp;</span><span style="color: rgb(0, 0, 255);">as</span><span style="color: rgb(0, 0, 0);">&nbsp;T;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;summary&gt;</span><span style="color: rgb(0, 128, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;查找某种类型的子孙节点<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;/summary&gt;</span><span style="color: rgb(0, 128, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;typeparam&nbsp;name="T"&gt;</span><span style="color: rgb(0, 128, 0);">目标节点类型</span><span style="color: rgb(128, 128, 128);">&lt;/typeparam&gt;</span><span style="color: rgb(0, 128, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;param&nbsp;name="parent"&gt;</span><span style="color: rgb(0, 128, 0);">起始节点</span><span style="color: rgb(128, 128, 128);">&lt;/param&gt;</span><span style="color: rgb(0, 128, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 128, 128);">///</span><span style="color: rgb(0, 128, 0);">&nbsp;</span><span style="color: rgb(128, 128, 128);">&lt;returns&gt;</span><span style="color: rgb(0, 128, 0);">符合条件的节点集合</span><span style="color: rgb(128, 128, 128);">&lt;/returns&gt;</span><span style="color: rgb(128, 128, 128);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">&nbsp;IEnumerable</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;FindChildren</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">&nbsp;DependencyObject&nbsp;parent)&nbsp;</span><span style="color: rgb(0, 0, 255);">where</span><span style="color: rgb(0, 0, 0);">&nbsp;T&nbsp;:&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;count&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;VisualTreeHelper.GetChildrenCount(parent);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(count&nbsp;</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 0, 0);">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">&nbsp;(var&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 0, 0);">;&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;count;&nbsp;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;child&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;VisualTreeHelper.GetChild(parent,&nbsp;i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;t&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;child&nbsp;</span><span style="color: rgb(0, 0, 255);">as</span><span style="color: rgb(0, 0, 0);">&nbsp;T;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(t&nbsp;</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">yield</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;t;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;children&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;FindChildren</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">T</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">(child);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">foreach</span><span style="color: rgb(0, 0, 0);">&nbsp;(var&nbsp;item&nbsp;</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">&nbsp;children)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">yield</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;item;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br></span></div><br><br>使用方法很简单。比如（还是拿对话框来举例）：<br><br><div class="cnblogs_code"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">IDialogHost&nbsp;host&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.FindAncestor</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">IDialogHost</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">();<br></span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(host&nbsp;</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;host.ShowModalDialog(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">);<br>}</span></div><br><br>over.<br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1249523.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41292/" target="_blank">[新闻]微软称Windows 7开发很顺利 IE 8年底上市</a>]]></description></item><item><title>Scott Guthrie 写的 Silverlight 教程索引</title><link>http://www.cnblogs.com/RChen/archive/2008/07/22/1248514.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Tue, 22 Jul 2008 02:39:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/22/1248514.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1248514.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/22/1248514.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1248514.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1248514.html</trackback:ping><description><![CDATA[Scott Guthrie的《<a href="http://blog.joycode.com/scottgu/archive/2008/02/23/114891.aspx">Silverlight 2初览</a>》中的八篇教程的中文版:<br><ul><li><a target="_blank" href="http://blog.joycode.com/scottgu/archive/2008/02/23/114894.aspx">第一部分：使用Silverlight 2 和 VS 2008创建“Hello World”程序 </a></li><li><a target="_blank" href="http://blog.joycode.com/scottgu/archive/2008/02/24/114898.aspx">第二部分：使用布局管理 </a>(<a target="_blank" href="http://rchen.cnblogs.com/">木野狐</a>译) </li><li><a target="_blank" href="http://blog.joycode.com/scottgu/archive/2008/02/24/114896.aspx">第三部分：使用 Networking取回数据并填充DataGrid</a> </li><li><a target="_blank" href="http://blog.joycode.com/scottgu/archive/2008/02/29/114915.aspx">第四部分：使用 Style 元素更好地封装观感</a> (<a target="_blank" href="http://rchen.cnblogs.com/">木野狐</a>译) </li><li><a target="_blank" href="http://blog.joycode.com/scottgu/archive/2008/02/29/114913.aspx">第五部分：用 ListBox 和 DataBinding 显示列表数据</a> (<a target="_blank" href="http://rchen.cnblogs.com/">木野狐</a>译) </li><li><a target="_blank" href="http://blog.joycode.com/scottgu/archive/2008/02/29/114917.aspx">第六部分：使用用户控件实现主从表场景</a> </li><li><a target="_blank" href="http://blog.joycode.com/scottgu/archive/2008/02/29/114916.aspx">第七部分：使用控件模板定制控件的观感 </a></li><li><a target="_blank" href="http://blog.joycode.com/scottgu/archive/2008/02/25/114901.aspx">第八部分：使用WPF创建一个Digg桌面应用 </a></li></ul><br>另外几篇教程：<br><br><a id="ctl00_MainContent_ViewPost1_TitleUrl" title="Title of this entry." href="http://blog.joycode.com/scottgu/archive/2008/03/02/114920.aspx">使用Expression Blend开发Silverlight 2应用 -- 初览</a><br><br><a id="ctl00_MainContent_ViewPost1_TitleUrl" title="Title of this entry." href="http://blog.joycode.com/scottgu/archive/2008/04/03/115046.aspx">在Silverlight中做单元测试</a><br><br><a id="ctl00_MainContent_ViewPost1_TitleUrl" title="Title of this entry." href="http://blog.joycode.com/scottgu/archive/2008/04/05/115049.aspx">技巧/诀窍： 创建和使用Silverlight和WPF 用户控件</a><br><br><a id="ctl00_MainContent_ViewPost1_TitleUrl" title="Title of this entry." href="http://blog.joycode.com/scottgu/archive/2008/06/09/115138.aspx">Silverlight 2 Beta2发布了</a><br><br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1248514.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41291/" target="_blank">[新闻]中国SNS捱过严冬 未来十八个月决定SNS生死</a>]]></description></item><item><title>Silverlight 文章收集</title><link>http://www.cnblogs.com/RChen/archive/2008/07/22/1248503.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Tue, 22 Jul 2008 02:32:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/22/1248503.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1248503.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/22/1248503.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1248503.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1248503.html</trackback:ping><description><![CDATA[<div class="PostTitle">
			(以下内容全部整理自博客堂 Scott gu 博客中文版)<br><br><br><a id="ctl00_MainContent_ViewPost1_TitleUrl" title="Title of this entry." href="http://blog.joycode.com/scottgu/archive/2008/04/04/115048.aspx">Silverlight技巧，诀窍，教程和链接</a>
		</div>
		



		<p>【原文地址】<a title="在Silverlight中做单元测试" href="http://weblogs.asp.net/scottgu/pages/silverlight-posts.aspx">Silverlight Tips, Tricks, Tutorials and Links Page </a></p> <p>我将使用本页链接到有关Silverlight 2的文章和贴子（包括我写的和别人写的），请经常回来查看新的内容，因为我才开始。 </p> <h3><u>入门教程</u></h3> <ul><li> <p><a href="http://blog.joycode.com/scottgu/archive/2008/02/23/114891.aspx" target="_blank" mce_href="http://blog.joycode.com/scottgu/archive/2008/02/23/114891.aspx">Silverlight 2 初览</a>: 我建议先读这个贴子，如果你正考虑开始Silverlight 2开发的话。该文不仅对Silverlight 2提供的功能做了高层次的描述，还链接到了一个<a href="http://blog.joycode.com/scottgu/archive/2008/02/29/114918.aspx" target="_blank" mce_href="http://blog.joycode.com/scottgu/archive/2008/02/29/114918.aspx">八个贴子的系列教程</a>，该教程对如何建造一个Digg客户端例程做了示范。这些教程贴子对Silverlight 2和WPF开发的概念提供了很好的介绍。</p></li></ul> <ul><li> <p><a href="http://blog.joycode.com/scottgu/archive/2008/03/02/114920.aspx" target="_blank" mce_href="http://blog.joycode.com/scottgu/archive/2008/03/02/114920.aspx">使用Expression Blend开发Silverlight 2应用 -- 初览</a>: 我建议下载Expression Blend 2.5 三月份预览版，按本教程贴子的步骤进行。我认为它很好地展示了Expression Blend的一些常见功能，用它建造了一个IM聊天客户端例程。</p></li></ul> <ul><li> <p><a href="http://www.jeff.wilcox.name/2008/03/31/silverlight2-unit-testing/" target="_blank" mce_href="http://www.jeff.wilcox.name/2008/03/31/silverlight2-unit-testing/">Unit Testing with Silverlight 2</a>: Silverlight开发团队的Jeff Wilcox有一篇精彩贴子，讨论如何使用Silverlight SDK中的单元测试框架单元测试Silverlight 2应用。</p></li></ul> <h3><u>入门讲座</u></h3> <ul><li> <p><a href="http://blogs.msdn.com/mharsh/archive/2008/03/05/slides-and-demos-from-my-mix-08-talk.aspx" target="_blank" mce_href="http://blogs.msdn.com/mharsh/archive/2008/03/05/slides-and-demos-from-my-mix-08-talk.aspx">Building Rich Internet Applications with Silverlight (Part 1 and 2)</a>: Joe Stegman和Mike Harsh在MIX 08上做了这分成2个部分的讲座， 讨论如何使用Silverlight建造应用。你可以使用上面的链接观看他们讲座的录像和下载相关讲义和示范例程。</p></li></ul> <ul><li> <p><a href="http://scorbs.com/2008/03/09/mix08-creating-rich-dynamic-user-interfaces-with-silverlight-2-controls/" target="_blank" mce_href="http://scorbs.com/2008/03/09/mix08-creating-rich-dynamic-user-interfaces-with-silverlight-2-controls/">Creating Rich, Dynamic User Interfaces with Silverlight 2 Controls</a>: Karen Corby在MIX 08上有个极棒的讲座，很好地解释了样式，控件模板，用户控件等等。你可以在<a href="http://scorbs.com/2008/03/14/flickrviewr/" target="_blank" mce_href="http://scorbs.com/2008/03/14/flickrviewr/">这里</a>运行和下载她完整的FlickR应用。</p></li></ul> <ul><li> <p><a href="http://weblogs.asp.net/scottgu/archive/2008/03/09/my-presentations-in-arizona-this-tuesday.aspx" target="_blank" mce_href="http://weblogs.asp.net/scottgu/archive/2008/03/09/my-presentations-in-arizona-this-tuesday.aspx">我的Silverlight入门讲座</a>: 你可以下载我最近在亚利桑那做的“Silverlight 2入门”讲座的讲义和示范例程，请随意在你自己的讲座中重用这些讲义。</p></li></ul> <h3><u>文档链接</u></h3> <ul><li> <p><a href="http://silverlight.net/quickstarts/managed.aspx" target="_blank" mce_href="http://silverlight.net/quickstarts/managed.aspx">Silverlight 2 QuickStart Tutorials</a>: 这些示范教程在上手Silverlight时会非常有用。</p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/brada/archive/2008/03/16/silverlight-2-developer-poster.aspx" target="_blank" mce_href="http://blogs.msdn.com/brada/archive/2008/03/16/silverlight-2-developer-poster.aspx">Silverlight 2 Developer Poster:</a> 下载和打印Silverlight 2开发者海报。</p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/sburke/archive/2008/03/05/silverlight-2-beta-1-controls-available-including-source-and-unit-tests.aspx" target="_blank" mce_href="http://blogs.msdn.com/sburke/archive/2008/03/05/silverlight-2-beta-1-controls-available-including-source-and-unit-tests.aspx">Silverlight Control Source and Unit Tests</a>: Shawn Burke提供了内置的Silverlight控件的源码以及相关单元测试的链接。 </p></li></ul> <ul><li> <p><a href="http://msdn2.microsoft.com/en-us/library/bb404700.aspx" target="_blank" mce_href="http://msdn2.microsoft.com/en-us/library/bb404700.aspx">MSDN Silverlight 2 Beta1 Online Documentation</a>: 这个网页提供了正式的Silverlight 2文档的链接。你可以在<a href="http://blogs.msdn.com/silverlight_sdk/archive/2008/03/03/silverlight-offline-documentation-march-2008.aspx" target="_blank" mce_href="http://blogs.msdn.com/silverlight_sdk/archive/2008/03/03/silverlight-offline-documentation-march-2008.aspx">这里</a>下载离线版本。</p></li></ul> <h3><u>教程和例程</u></h3> <ul><li> <p><a href="http://silverlight.net/Learn/videocat.aspx?cat=2" target="_blank" mce_href="http://silverlight.net/Learn/videocat.aspx?cat=2">"How Do I?" with Silverlight</a>: 这个链接连到了含有一堆Silverlight 2录像教程的网页。</p></li></ul> <ul><li> <p><a href="http://sessions.visitmix.com/?selectedSearch=Hard%20Rock&amp;searchPlink=true" target="_blank">Hard Rock Memorabilia Sample</a>: Vertigo Software公司的Scott Stanfield讨论三月份发布的使用Silverlight 2建造的很酷的<a href="http://memorabilia.hardrock.com/" target="_blank" mce_href="http://memorabilia.hardrock.com/">Hard Rock Memorabilia</a>网站。</p></li></ul> <ul><li> <p><a href="http://geekswithblogs.net/SilverBlog/archive/2008/03/25/silverlight-2.0-application-with-multiscaleimage-control-and-deep-zoom-composer.aspx" target="_blank" mce_href="http://geekswithblogs.net/SilverBlog/archive/2008/03/25/silverlight-2.0-application-with-multiscaleimage-control-and-deep-zoom-composer.aspx">Using Deep Zoom with Silverlight 2</a>: Jacek Ciereszko有一个很好的博客贴子，描述了如何使用Silverlight 2的 “Deep Zoom”功能实现跟Hard Rock例程类似的图像放大功能。</p></li></ul> <ul><li> <p><a href="http://silverlight.net/blogs/msnow/archive/2008/03/25/introduction.aspx" target="_blank" mce_href="http://silverlight.net/blogs/msnow/archive/2008/03/25/introduction.aspx">Game Programming with Silverlight:</a> Mike Snow正打造一个分成十一个部分的博客系列，讨论如何使用Silverlight开发在线游戏。</p></li></ul> <ul><li> <p><a href="http://www.jeff.wilcox.name/2008/04/01/link-cloud/" target="_blank" mce_href="http://www.jeff.wilcox.name/2008/04/01/link-cloud/">Homepage "Link Cloud" application</a>: Jeff Wilcox讨论他建造的一个很酷的标签云应用。</p></li></ul> <h3><u>部署体验</u></h3> <ul><li> <p><a href="http://timheuer.com/blog/archive/2008/03/25/creating-a-great-silverlight-deployment-experience.aspx" target="_blank" mce_href="http://timheuer.com/blog/archive/2008/03/25/creating-a-great-silverlight-deployment-experience.aspx">Providing a Great Silverlight Deployment Experience</a>: Tim Heuer有个很好的贴子，讨论可以为你所用的技术来优化Silverlight安装体验。</p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/brada/archive/2008/03/14/using-silverlight-2-on-a-production-web-server.aspx" target="_blank" mce_href="http://blogs.msdn.com/brada/archive/2008/03/14/using-silverlight-2-on-a-production-web-server.aspx">Using Silverlight 2 on a Production Web Server:</a> Brad Abrams有个很好的贴子，讨论在把Silverlight .xap文件拷贝到IIS web服务器时需要注意的几件事情。 </p></li></ul> <h3><u>控件模板</u></h3> <ul><li> <p><a href="http://mattberseth.com/blog/2008/03/creating_a_custom_skin_for_sil.html" target="_blank" mce_href="http://mattberseth.com/blog/2008/03/creating_a_custom_skin_for_sil.html">Creating a Custom Skin for Silverlight's Button Control:</a> Matt Berseth的一个精彩好贴，讨论Silverlight控件的皮肤和样式功能。 </p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/sburke/archive/2008/03/22/tutorial-writing-a-templated-silverlight-2-control.aspx" target="_blank" mce_href="http://blogs.msdn.com/sburke/archive/2008/03/22/tutorial-writing-a-templated-silverlight-2-control.aspx">Writing a Templated Silverlight Control</a>: Shawn Burke有个精彩贴子，详细描述了如何创建定制的Silverlight模板控件。</p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/delay/archive/2008/03/22/improving-everyone-s-access-to-silverlight-2-s-generic-xaml-resources-silverlightdefaultstylebrowser-tool-and-source-code.aspx" target="_blank" mce_href="http://blogs.msdn.com/delay/archive/2008/03/22/improving-everyone-s-access-to-silverlight-2-s-generic-xaml-resources-silverlightdefaultstylebrowser-tool-and-source-code.aspx">Improving Access to Silverlight's Generic.xaml Resources</a> (也阅读 <a href="http://blogs.msdn.com/delay/archive/2008/03/22/improved-access-to-silverlight-2-s-generic-xaml-resources-silverlightdefaultstylebrowser-available-via-clickonce.aspx" target="_blank" mce_href="http://blogs.msdn.com/delay/archive/2008/03/22/improved-access-to-silverlight-2-s-generic-xaml-resources-silverlightdefaultstylebrowser-available-via-clickonce.aspx">这里的Part 2</a>): David Anson有个很棒的工具，示范如何查看和提取内置Silverlight控件的默认XAML样式。</p></li></ul> <h3><u>ListBox和ScrollViewer场景</u></h3> <ul><li> <p><a href="http://blogs.msdn.com/delay/archive/2008/03/05/lb-sv-faq-examples-notes-tips-and-more-for-silverlight-2-beta-1-s-listbox-and-scrollviewer-controls.aspx" target="_blank" mce_href="http://blogs.msdn.com/delay/archive/2008/03/05/lb-sv-faq-examples-notes-tips-and-more-for-silverlight-2-beta-1-s-listbox-and-scrollviewer-controls.aspx">Ultimate ListBox and ScrollViewer Frequently Asked Questions Guide</a>: David Anson，Silverlight ListBox和ScrollViewer控件的开发者，编篡了这个很棒的，关于所有这些控件的FAQ以及你可以使用它们的场景。</p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/delay/archive/2008/03/12/lb-sv-why-three-wacky-uses-for-silverlight-2-s-listbox-and-scrollviewer.aspx" target="_blank" mce_href="http://blogs.msdn.com/delay/archive/2008/03/12/lb-sv-why-three-wacky-uses-for-silverlight-2-s-listbox-and-scrollviewer.aspx">Cool (wacky) uses of the ListBox and ScrollViewer controls</a>: David Anson的又一篇精彩贴子，展示了数据和控件模板的灵活性。</p></li></ul> <h3><u>DataGrid场景</u></h3> <ul><li> <p><a href="http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx" target="_blank" mce_href="http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx">Using the Silverlight DataGrid</a> and <a href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx" target="_blank" mce_href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx">Defining Columns for a Silverlight DataGrid</a>: Scott Morrison开始了一个精彩贴子系列，描述如何使用新的Silverlight 2 DataGrid控件（他是相关项目的主管，绝对精通！）</p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/swiss_dpe_team/archive/2008/03/17/silverlight-2-beta1-wcf-linq-to-sql-a-powerfull-combination.aspx" target="_blank" mce_href="http://blogs.msdn.com/swiss_dpe_team/archive/2008/03/17/silverlight-2-beta1-wcf-linq-to-sql-a-powerfull-combination.aspx">Using Silverlight 2's DataGrid with WCF + LINQ to SQL</a>:
这个15分钟的录像博客示范了如何在服务器上建造一个LINQ to
SQL对象模型，然后用WCF将其发布，然后示范了如何建造一个使用了新的Silverlight
DataGrid控件的Silverlight客户端，该客户端调用WCF服务获取LINQ to SQL数据，将其绑定到DataGrid上。 </p></li></ul> <ul><li> <p><a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/27/10290.aspx" target="_blank" mce_href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/27/10290.aspx">Simple Editing of Web Service Data in a DataGrid:</a>
Mike Taulty有一篇好贴，展示如何在服务器上建造WCF服务，然后从Silverlight
2客户端使用它来获取数据，绑定到DataGrid，允许用户更新数据行，添加/删除数据行，然后使用 Silverlight 2
Beta1将数据保存到服务器上。 </p></li></ul> <ul><li> <p><a href="http://mattberseth.com/blog/2008/03/sorting_with_silverlight_2s_da.html" target="_blank" mce_href="http://mattberseth.com/blog/2008/03/sorting_with_silverlight_2s_da.html">Sorting with Silverlight 2's DataGrid Control:</a> Silverlight 2 Beta1中的DataGrid控件还没有内置的列数据排序支持（将在Beta2中提供），但这并没有阻止Matt Berseth！ 在这个贴子里，他展示了如何使用一个定制的header列方法来实现排序。也看一下Matt的 <a href="http://mattberseth.com/blog/2008/03/a_quick_look_at_silverlight_2s.html" mce_href="http://mattberseth.com/blog/2008/03/a_quick_look_at_silverlight_2s.html">这里</a>的贴子，该文提供了一个DataGrid测试页面，展示了目前DataGrid的若干特性。 </p></li></ul> <h3><u>Web Services 和 Networking</u></h3> <ul><li> <p><a href="http://blogs.msdn.com/silverlight_sdk/archive/2008/03/27/web-services-and-silverlight.aspx" target="_blank" mce_href="http://blogs.msdn.com/silverlight_sdk/archive/2008/03/27/web-services-and-silverlight.aspx">Web Services and Silverlight</a>: 这个有用的贴子讨论了如何在Silverlight中使用web服务，并且提供了相关快速入门例程和文档的链接。</p></li></ul> <ul><li> <p><a href="http://timheuer.com/blog/archive/2008/03/14/calling-web-services-with-silverlight-2.aspx" target="_blank" mce_href="http://timheuer.com/blog/archive/2008/03/14/calling-web-services-with-silverlight-2.aspx">Calling Web Services with Silverlight 2 (Part 1)</a> and <a href="http://timheuer.com/blog/archive/2008/03/19/calling-services-with-silverlight-part-2.aspx" target="_blank" mce_href="http://timheuer.com/blog/archive/2008/03/19/calling-services-with-silverlight-part-2.aspx">(Part 2)</a>: Tim Heuer的几篇精彩贴子，讨论如何使用Silverlight调用web服务。</p></li></ul> <h3><u>Video场景</u></h3> <ul><li> <p><a href="http://sessions.visitmix.com/?selectedSearch=Encoding%20Video%20for%20Microsoft%20Silverlight&amp;searchPlink=true" target="_blank">Encoding Video for Microsoft Silverlight Delivery</a>: Ben Waggoner在MIX 08上的讲座，讨论编码Silverlight录像的最佳实践。</p></li></ul> <h3><u>Accessibility 和 508相容性</u></h3> <ul><li> <p><a href="http://www.visitmix.com/blogs/Joshua/Silverlight-2-Accessibility-with-Mark-Rideout/" target="_blank" mce_href="http://www.visitmix.com/blogs/Joshua/Silverlight-2-Accessibility-with-Mark-Rideout/">Accessibility in Silverlight 2</a>: Silverlight开发团队的Mark Rideout讨论 Silverlight 2 中的accessibility支持，以及如何使用Silverlight建造与section 508相容的accessible方案。</p></li></ul><br>============================================================<br><br>2008.5.20 链接<br><br><h3><u>Silverlight</u></h3> <ul><li> <p><a href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/05/15/10402.aspx" target="_blank">50 New Silverlight 2 Beta 1 Screencasts:</a> Mike Taulty 和 Mike Ormond 在他们的“业余时间”里录制了50个很棒的讨论Silverlight 2的教程屏播，太棒了！ </p></li></ul> <ul><li> <p><a href="http://www.nikhilk.net/Entry.aspx?id=195" target="_blank">AutoComplete for Silverlight TextBoxes</a>: Nikhil Kothari有一篇很好的博客贴子，示范了他是如何建造一个Silverlight的自动完成行为控件的。 </p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/swiss_dpe_team/archive/2008/05/09/scrolling-through-large-resultset-with-silverlight-2-beta1-and-linq-to-sql.aspx" target="_blank">Scrolling through Large Resultsets with Silverlight 2 and LINQ to SQL</a>: Swiss MSDN队有一篇很好的博客贴子，示范了如何使用Silverlight DataGrid 和 LINQ to SQL对大数据集进行卷动浏览。 </p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/delay/archive/2008/05/04/ivalueconverter-the-swiss-army-knife-of-bindings-propertyviewer-sample-is-a-wpf-silverlight-visualization-and-debugging-aid.aspx" target="_blank">IValueConverter: The Swiss Army Knife of Bindings</a>: David Anson有一篇很有用的博客贴子和相应例程，示范了如何使用Silverlight 和 WPF中的IValueConverter功能，支持对复杂对象更丰富的绑定。 </p></li></ul> <ul><li> <p><a href="http://petermcg.wordpress.com/2008/05/18/silverlight-20-pie-chart/" target="_blank">Silverlight 2 Pie Chart:</a> Peter McGrattan贴出了一个很好的控件和相应文章，示范如何使用他编写的一个新Silverlight图表控件。 </p></li></ul><br>=================================================<br><br>2008.4.28 链接<br><br><h3><u>Silverlight</u></h3> <ul><li> <p><a href="http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx" target="_blank">Defining Silverlight DataGrid Columns at Runtime</a>: Silverlight开发团队的Scott Morrison有一篇很酷的贴子，讨论如何在运行时通过代码来定义Silverlight DataGrid的列，访问我的 <a href="http://weblogs.asp.net/scottgu/pages/silverlight-posts.aspx" target="_blank">Silverlight链接网页</a>（<a href="http://blog.joycode.com/scottgu/archive/2008/04/04/115048.aspx" target="_blank">中文版</a>），找找更多关于DataGrid的贴子。 </p></li></ul> <ul><li> <p><a href="http://scorbs.com/2008/04/05/silverlight-http-networking-stack-part-1-site-of-origin-communication" target="_blank">Silverlight HTTP Networking Stack</a> (<a href="http://scorbs.com/2008/04/05/silverlight-http-networking-stack-part-1-site-of-origin-communication" target="_blank">Part 1</a>), (<a href="http://scorbs.com/2008/04/15/silverlight-http-networking-stack-part-2-cross-domain-communication-overview/" target="_blank">Part 2</a>), (<a href="http://scorbs.com/2008/04/22/silverlight-http-networking-stack-part-3-configuring-a-cross-domain-policy-file/" target="_blank">Part 3</a>): Silverlight开发团队的 Karen Corby 撰写了一个分成3个部分的精彩博客系列，讨论新的Silverlight 2 networking stack以及跨域安全是如何在其中工作的。</p></li></ul> <ul><li> <p><a href="http://weblogs.asp.net/dwahlin/archive/2008/04/10/pushing-data-to-a-silverlight-client-with-sockets-part-i.aspx" target="_blank">Pushing Data to a Silverlight Client with Sockets (Part 1)</a> and <a href="http://weblogs.asp.net/dwahlin/archive/2008/04/13/pushing-data-to-a-silverlight-client-with-sockets-part-ii.aspx" target="_blank">(Part 2)</a>: Dan Wahlin示范了如何实现一个GameStream socket服务器，如何使用Silverlight 2中内置的network sockets支持从Silverlight客户端连接到该服务器。 </p></li></ul> <ul><li> <p><a href="http://weblogs.asp.net/dwahlin/archive/2008/04/27/silverlight-the-song.aspx" target="_blank">Silverlight - the Song</a>: Spike Xavier和Dan Wahlin 又发表了一首独一无二的歌曲，《Silverlight之歌》，:-)</p></li></ul><br>===========================================================<br><br>2008.4.11 链接<br><h3><u>Silverlight</u></h3> <ul><li> <p><a href="http://geekswithblogs.net/WynApseTechnicalMusings/Default.aspx" target="_blank">Dave Campbell's Excellent Silverlight Link Series</a>: Dave Campbell定期贴出网上新Silverlight文章和内容的系列链接，我高度推荐订阅他的博客，如果你想要了解最新的Silverlight文章和贴子的话。</p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/jasonz/archive/2008/04/04/silverlight-2-map-datagrid-demo-part-2.aspx" target="_blank">Silverlight 2 Map / DataGrid Tutorial</a>: Jason Zander有一个精彩的二部分Silverlight教程，示范了如何建造数据驱动的应用，结合了地图控件和datagrid来过滤和分析数据。</p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/swiss_dpe_team/archive/2008/04/04/crud-operations-with-optimistic-locking-using-silverlight-2-beta1-wcf-and-linq-to-sql-inserts-updates-and-deletes.aspx" target="_blank">CRUD operations with Silverlight 2, WCF and LINQ to SQL</a>: Swiss MSDN开发团队的Ronnie Saurenmann有一个很棒的录像，展示了一下如何使用Silverlight 2通过WCF连接到LINQ to SQL后端来支持插入，更新和删除数据。</p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/sburke/archive/2008/03/22/tutorial-writing-a-templated-silverlight-2-control.aspx" target="_blank">Writing a Templated Silverlight 2 Control</a>: Shawn Burke有一篇精彩的教程贴子，按部就班地示范如何建造一个Silverlight模板控件来实现一个可缩放的控件。</p></li></ul><br>=======================================================<br><br>2008.3.28 链接<br><h3><u>Silverlight</u></h3>
<ul><li>
    <p><a target="_blank" href="http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx">Using the Silverlight DataGrid</a> and <a target="_blank" href="http://blogs.msdn.com/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx">Defining Columns for a Silverlight DataGrid</a>: Scott Morrison开始了一个很精彩的贴子系列，描述如何使用新的Silverlight 2 DataGrid控件（他是该控件的项目主管，所以他绝对精通！）。</p>
    </li></ul>
<ul><li>
    <p><a target="_blank" href="http://blogs.msdn.com/swiss_dpe_team/archive/2008/03/17/silverlight-2-beta1-wcf-linq-to-sql-a-powerfull-combination.aspx">Using Silverlight 2's DataGrid with WCF + LINQ to SQL</a>:
这个15分钟的录像博客示范了如何在服务器上建造一个LINQ to
SQL对象模型，然后用WCF将其发布，然后示范了如何建造一个使用了新的Silverlight
DataGrid控件的Silverlight客户端，该客户端调用WCF服务获取LINQ to SQL数据，将其绑定到DataGrid上。</p>
    </li></ul>
<ul><li>
    <p><a target="_blank" href="http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/27/10290.aspx">Simple Editing of Web Service Data in a DataGrid:</a>
Mike Taulty有一篇好贴，展示如何在服务器上建造WCF服务，然后从Silverlight
2客户端使用它来获取数据，绑定到DataGrid，允许用户更新数据行，添加/删除数据行，然后使用 Silverlight 2
Beta1将数据保存到服务器上。</p>
    </li></ul>
<ul><li>
    <p><a target="_blank" href="http://mattberseth.com/blog/2008/03/sorting_with_silverlight_2s_da.html">Sorting with Silverlight 2's DataGrid Control:</a> Silverlight 2 Beta1中的DataGrid控件还没有内置的列数据排序支持（将在Beta2中提供）。但这并没有阻止Matt Berseth！ 在这个贴子里，他展示了如何使用一个定制的header列方法来实现排序。也看一下Matt的<a target="_blank" href="http://mattberseth.com/blog/2008/03/a_quick_look_at_silverlight_2s.html">这里</a>的贴子，该文提供了一个DataGrid测试页面，展示了目前DataGrid的若干特性。 </p>
    </li></ul>
<ul><li>
    <p><a target="_blank" href="http://www.visifire.com/silverlight_charts_gallery.php">Open Source Silverlight Charts with VisiFire</a>: Silverlight还没有内置的图表控件。好消息是， Webyog公司刚发布了一套非常酷的开源Silverlight图表控件（带有动画支持），允许你轻松地建造好看的图表，他们的模型极大地方便了在现有的HTML或AJAX应用中图表组件的使用。</p>
    </li></ul>=====================================================<br><br>2007.11.17 链接<br><br><h3><u>WPF and Silverlight</u></h3> <ul><li> <p><a href="http://www.codeplex.com/SilverlightRTL" target="_blank">Silverlight 1.1 Hebrew and Arabic Language Support</a>: 目前Silverlight还不支持从右到左的文字布局。Justin-Josef Angel启动了一个绝对惊异的CodePlex项目提供这样的支持。现在就去<a href="http://www.codeplex.com/SilverlightRTL" target="_blank">CodePlex</a>下载代码，在<a href="http://blogs.microsoft.co.il/blogs/justinangel/archive/2007/10/26/silverlight-1-1-hebrew-and-arabic-language-support-silverlightrtl.aspx" target="_blank">这里</a>阅读他的有关详细教程吧。</p></li></ul> <ul><li> <p><a href="http://channel9.msdn.com/ShowPost.aspx?PostID=346845" target="_blank">.NET 3.5 Add-In Model</a>: Jack Gudenkauf是我开发团队的开发人员，他负责.NET 3.5中新的System.AddIn命名空间的设计。 这个命名空间方便你往客户端应用中建造插件的扩展性。此外，它还允许你跨越应用域和进程边界隔离插件和WPF控件（<a href="http://blogs.msdn.com/clraddins/archive/2007/08/06/appdomain-isolated-wpf-add-ins-jesse-kaplan.aspx" target="_blank">这里是一个这样的例程</a>）。观看Jack在Channel9的录像以了解详情。</p></li></ul> <ul><li> <p><a href="http://msdn.microsoft.com/msdnmag/issues/07/12/DataPoints/" target="_blank">Data Binding in WPF</a>: MSDN杂志上John Papa撰写的一篇好文章，描述了WPF绑定模型的工作原理的一些基本知识。Josh Twist也在<a href="http://www.thejoyofcode.com/Reason_Number_2._Databinding.aspx" target="_blank">这里</a> 和 <a href="http://www.thejoyofcode.com/Reason_3._DataTemplates.aspx" target="_blank">这里</a> 撰写了一些很好的WPF数据绑定的文章。想进一步学习WPF的话，我极力推荐 <a href="http://www.amazon.com/gp/product/0672328917?ie=UTF8&amp;tag=scoblo04-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=0672328917" target="_blank">Adam Nathan的佳作《WPF Unleashed》</a> (在Amazon.com上45个评语之后还是5星级)。Silverlight 1.1的下一个公开版将支持和WPF完整版中一样强大的数据绑定模型，将极大地方便数据应用的建立。</p></li></ul>=================================================================<br><br>2007.10.25 链接<br><br><h3><u>Silverlight</u></h3> <ul><li> <p><a href="http://www.microsoft.com/uk/mix07/agenda.aspx" target="_blank">使用.NET打造Silverlight应用的MIX UK录像</a>: 最近举行的MIX UK大会上的录像已经上线，可以为任何人免费观赏。如果你对Siliverlight感兴趣，我建议你观看我的使用.NET打造Silverlight应用的讲座的录像（分成第一、第二部分）。你可以在<a href="http://weblogs.asp.net/scottgu/archive/2007/09/12/slides-samples-from-my-talks-from-mix-uk-building-silverlight-apps-with-net-and-building-asp-net-apps-with-vs-2008.aspx" target="_blank">这里</a>下载讲义和例程。 </p></li></ul> <ul><li> <p><a href="http://www.adefwebserver.com/DotNetNukeHELP/Misc/SilverlightVR/" target="_blank">使用了Jeff Paries 动画引擎的SilverlightVR 3D</a>: 这是一个非常，非常酷的样例和代码库，它允许你创建允许用户旋转和转换3D对象的Silverlight应用。 </p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/delay/archive/2007/10/15/something-fun-for-the-little-ones-silverlightkidsdoodler-develops-mouse-skills.aspx" target="_blank">Silverlight Kids Doodler 例程</a>: David Anson 发表了一个很精致的样例，示范如何在Silverlight里建造一个精致的绘画程序。特别适宜儿童，:-)。 </p></li></ul> <ul><li> <p><a href="http://www.gleblanc.eu/post/Available-tutorials.aspx" target="_blank">Silverlight精彩教程</a>: Gerard Leblanc著有一个精彩的博客，经常发表关于Silverlight的博客贴子。去看一下他的一些教程的列表。 </p></li></ul>=======================================================<br><br>2007.10.8 链接<br><br><h3><u>Silverlight</u></h3> <ul><li> <p><a href="http://www.amazon.com/gp/product/0672330075/104-9219624-7383145?ie=UTF8&amp;tag=scoblo04-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=0672330075" target="_blank">《Silverlight Unleashed》 一书将于本周出版</a>: Adam Nathan的佳作《<a href="http://www.amazon.com/gp/product/0672330075/104-9219624-7383145?ie=UTF8&amp;tag=scoblo04-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=0672330075" target="_blank">Silverlight Unleashed</a>》将于本周稍后（10月11日）出版 。Adam 写的《<a href="http://www.amazon.com/gp/product/0672328917/104-9219624-7383145?ie=UTF8&amp;tag=scoblo04-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=0672328917" target="_blank">WPF Unleashed</a>》畅销书，是今年Amazon最畅销的编程书之一，他还是Microsoft PopFly 服务（是用Silverlight建造的）的核心架构师。我非常期待拿到这本新书！ </p> <p><a href="http://www.amazon.com/gp/product/0672330075/104-9219624-7383145?ie=UTF8&amp;tag=scoblo04-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=0672330075" target="_blank" atomicselection="true"><img src="http://ec1.images-amazon.com/images/I/51ksSqvQswL._AA240_.jpg"></a> </p></li></ul> <ul><li> <p><a href="http://blog.donburnett.com/2007/09/silverlight-video-revolution-continues.html" target="_blank">精妙的Quiksilver录像体验</a>: 这是个非常酷的Silverlight网站，展示了使用Silverlight打造精美的录像体验。非常棒！ </p></li></ul> <ul><li> <p><a href="http://www.vectorform.com/silverlight/" target="_blank">Vectorform Labs Silverlight 样例</a>: Vectorform 最近刚发布了一些非常棒的Silverlight例程（带完整的源代码），绝对值得一看。 </p></li></ul> <ul><li> <p><a href="http://www.codeplex.com/FarseerPhysics" target="_blank">Farseer物理引擎</a>: 这个免费的CodePlex项目提供了一个非常好的Silverlight 1.1 2D物理引擎。你可以在<a href="http://www.bluerosegames.com/farseersilverlightdemos" target="_blank">这里</a>看一些在线演示。 </p></li></ul> <ul><li> <p><a href="http://blogs.msdn.com/tims/archive/2007/09/28/deploying-silverlight-in-the-enterprise.aspx" target="_blank">在企业环境里部署Silverlight</a>: David Tesar 和Tim Sneath指出了一个非常好的文档，企业IT管理员可以用来学习如何在安全防范的企业环境里自动部署Silverlight。 </p></li></ul><br>=============================<br>其他文章：<br><br><a href="http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/Series/Silverlight2.aspx">Silverlight 2.0 发现之旅系列课程</a><br>http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/Series/Silverlight2.aspx<br><br><h1><font size="3"><a id="bp___v___bt___BlogTitle" class="headermaintitle" href="http://blogs.msdn.com/silverlightshanghai/default.aspx">CLR &amp; Silverlight上海研发团队的Blog</a></font></h1>http://blogs.msdn.com/silverlightshanghai/default.aspx<br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1248503.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41291/" target="_blank">[新闻]中国SNS捱过严冬 未来十八个月决定SNS生死</a>]]></description></item><item><title>[Silverlight] 一个易犯的错误：关于调用 WCF 服务</title><link>http://www.cnblogs.com/RChen/archive/2008/07/19/1246680.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Sat, 19 Jul 2008 08:36:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/19/1246680.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1246680.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/19/1246680.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1246680.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1246680.html</trackback:ping><description><![CDATA[<P>在采用 Silverlight 调用 WCF 的开发过程中，今天遇到一个错误。<BR>由于 Silverlight 中只支持异步方式的 WCF 调用，所以代码一般是这样子的：<BR><BR></P>
<DIV class=cnblogs_code><SPAN style="COLOR: #000000">var&nbsp;myServiceClient&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;MyServiceClient();<BR>myServiceClient.GetSomeDataCompleted&nbsp;</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">&nbsp;(sender,&nbsp;args)&nbsp;</SPAN><SPAN style="COLOR: #000000">=&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HtmlPage.Window.Alert(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">completed.</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">);<BR>};<BR>myServiceClient.GetSomeDataAsync();</SPAN></DIV>
<P>这样写是没有问题的。<BR><BR>但是有的朋友可能为了提高代码共用程度，而把 myServiceClient 这个 WCF 的客户端代理对象作为类的字段来定义，以便在多次调用中共享。比如<A href="http://www.cnblogs.com/lyj/archive/2008/04/23/1167852.html">这篇教程</A>中所说的：<BR><BR><FONT style="BACKGROUND-COLOR: #d3d3d3">“这一步比较复杂，这里分小点讨论。为了调用WCF服务，先定义一下全局变量。</FONT></P><FONT style="BACKGROUND-COLOR: #d3d3d3"><SPAN style="COLOR: #2b91af">AcademeServiceClient </SPAN>academeSClient;<BR>”</FONT><BR><BR>这样做有什么问题呢？<BR><BR>假设我们上面的代码是在一个按钮的点击事件处理函数里定义的，那么，就会导致每点击一次按钮就注册一次 GetSomeDataCompleted 的事件处理函数。最后你会发现点一次按钮，会重复多次执行回调函数。<BR><BR>所以还是不要共用 client 代理了，每次调用之前创建一个比较好。<BR>因为今天遇到了这个错误，在这里提醒一下大家。<BR><BR><img src ="http://www.cnblogs.com/RChen/aggbug/1246680.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41290/" target="_blank">[新闻]微软追求雅虎告一段落 与Facebook展开搜索合作</a>]]></description></item><item><title>[Silverlight] 改进 Nikhil Kothari 的换肤方案：允许自定义控件的皮肤定义</title><link>http://www.cnblogs.com/RChen/archive/2008/07/17/1245146.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Thu, 17 Jul 2008 06:02:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/17/1245146.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1245146.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/17/1245146.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1245146.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1245146.html</trackback:ping><description><![CDATA[摘要: 在 Silverlight 下换肤的实现 中，我介绍了 Nikhil Kothari 实现的一种 Theme 方案。但是实践了一下，我很快发现有个小小的缺陷。作者的皮肤定义是仅针对系统自带的控件的，如 Button, TextBox, CheckBox 等，而对于我们自定义的控件的换肤问题没有很好的解决。从下列代码中可见一斑：(/Framework/Applications/Theme.cs)Co&nbsp;&nbsp;<a href='http://www.cnblogs.com/RChen/archive/2008/07/17/1245146.html'>阅读全文</a><img src ="http://www.cnblogs.com/RChen/aggbug/1245146.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41289/" target="_blank">[新闻]百度C2C项目年底上线</a>]]></description></item><item><title>Silverlight 的文本框自动完成(AutoComplete)</title><link>http://www.cnblogs.com/RChen/archive/2008/07/17/1244786.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Wed, 16 Jul 2008 18:27:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/17/1244786.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1244786.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/17/1244786.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1244786.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1244786.html</trackback:ping><description><![CDATA[Nikhil Kothari 利用他开发的 behavior 框架实现了自动完成功能。并且支持多种形式的调用方式，很灵活。<br>具体见这里：<br><br>http://www.nikhilk.net/Silverlight-AutoComplete.aspx<br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1244786.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41289/" target="_blank">[新闻]百度C2C项目年底上线</a>]]></description></item><item><title>Silverlight 下换肤的实现</title><link>http://www.cnblogs.com/RChen/archive/2008/07/17/1244782.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Wed, 16 Jul 2008 17:41:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/17/1244782.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1244782.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/17/1244782.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1244782.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1244782.html</trackback:ping><description><![CDATA[Silverlight 目前控件要改变外观一般都通过 Style="{StaticResource SomeStyle}" 来指定，而不能统一设置一个默认的 Style. 为了重用，一般把 Style 都放到 App.xaml 的 Resources 字典中去。而 Style 的定义往往非常冗长，这样 App.xaml 就会变得非常臃肿，修改维护都很麻烦。并且，还不能支持多个控件批量切换 Style 的，总之弊端非常多。<br><br>幸好 Nikhil Kothari 想了个<a href="http://www.nikhilk.net/Silverlight-Themes.aspx">办法</a>解决了这个问题。在使用方式上，借鉴了 asp.net 的 Theme 机制。只要在 Silverlight 程序的根目录下定义一个 Themes 目录，并按要求往其中放入相关的皮肤文件即可。这里建议的方式是每一个控件一个单独的 xaml, 其中放了一个 UserControl. 之所以用 UserControl 的目的是为了能用 Expression Blend 进行可视化设计，非常直观。<br><br>主要实现思想：<br><br>1. 继承了一个自定义的 App 子类. 使用者需要将现有的 App.xaml 改成使用该类才行。<br>（同时这个 App 类还实现了根据 initParameters 在 xaml 中动态指定加载的 UserControl 和 Theme 的功能）<br>&nbsp;&nbsp; 其中设置一个 ThemeName 属性来定义 Theme 名称。<br><br>2. 在 App 启动时，根据这个属性名动态去加载相关 xaml 的 xml 文件，并解析之。这些皮肤的 xaml 文件在 VS 里是要把 Build Action 设置成 Content 的。这样可以生成到 xap 包里去，以便于加载。<br><br>3. 在读取多个 xaml 文件并解析的过程中对同样的 Style 根据优先级做了相应的覆盖合并。最终形成一个总的 xaml 文件内容。<br><br>4. 用 XamlReader 的 Load 方法加载最终的文档。将其中的资源都抽取出来，并塞到 App.Resources 字典里去。<br><br>5. 然后正常的控件视觉树开始创建。其中的视觉元素指定了 StaticResource 样式，这时它就能从 App 的资源字典里获取到皮肤样式。<br><br><br>注意：这里自始至终没有动态对控件指定 Style 的机制。因为 Silverlight 目前不支持。<br>这个解决方案的主要思想就是在视觉树加载之前，动态的修改了 App 中的资源，后续的样式应用机制仍然是 framework 默认的。<br><br>该方案的代码地址由 Nikhil Kothari 提供如下：<a href="http://www.nikhilk.net/Content/Posts/SilverlightThemes/Theming.zip">[下载]</a><br><br>原文地址：http://www.nikhilk.net/Silverlight-Themes.aspx<br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1244782.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41289/" target="_blank">[新闻]百度C2C项目年底上线</a>]]></description></item><item><title>Silverlight 下苹果(Mac OS)风格按钮的实现</title><link>http://www.cnblogs.com/RChen/archive/2008/07/11/1241122.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Fri, 11 Jul 2008 14:02:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/11/1241122.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1241122.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/11/1241122.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1241122.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1241122.html</trackback:ping><description><![CDATA[摘要: <p><img src="http://www.cnblogs.com/images/cnblogs_com/rchen/mac_2.jpg" align="right"/><br>   本文介绍在 Silverlight 2 beta 2 下如何实现 Mac 风格的按钮。<br></p>&nbsp;&nbsp;<a href='http://www.cnblogs.com/RChen/archive/2008/07/11/1241122.html'>阅读全文</a><img src ="http://www.cnblogs.com/RChen/aggbug/1241122.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41288/" target="_blank">[新闻]鲍尔默：微软每年至少投资25亿美元死拼Google</a>]]></description></item><item><title>Silverlight 之模态对话框的通用模拟</title><link>http://www.cnblogs.com/RChen/archive/2008/07/05/1236046.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Fri, 04 Jul 2008 17:29:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/05/1236046.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1236046.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/05/1236046.html#Feedback</comments><slash:comments>11</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1236046.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1236046.html</trackback:ping><description><![CDATA[摘要: <p><img src="/images/cnblogs_com/RChen/WindowsLiveWriter/Silverlight_175E/modaldialog2_2.jpg" width="100" align="right"/>Silverlight 给我们带来了如同 Winform 一样便捷的开发方式，然而在桌面应用程序中一个非常重要的元素——模态对话框，却不具备。<br>本文提供了一个简单的封装，以便更方便的实现模态对话框主/从调用的场景。<br></p>&nbsp;&nbsp;<a href='http://www.cnblogs.com/RChen/archive/2008/07/05/1236046.html'>阅读全文</a><img src ="http://www.cnblogs.com/RChen/aggbug/1236046.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41287/" target="_blank">[新闻]CNNIC发布《第22次中国互联网络发展状况统计报告》</a>]]></description></item><item><title>Silverlight 数据绑定 (2)：Source to Target</title><link>http://www.cnblogs.com/RChen/archive/2008/07/04/1235816.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Fri, 04 Jul 2008 08:58:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/04/1235816.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1235816.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/04/1235816.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1235816.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1235816.html</trackback:ping><description><![CDATA[<P>接着<A href="/RChen/archive/2008/07/03/1235039.html" target=_blank>上一篇</A>，在 Silverlight 中支持3种绑定：OneWay, TwoWay, OneTime. 默认是 OneWay.</P>
<P>其中 OneWay 表示仅仅从数据源绑定到目标(通常是 UI 对象)，单向的；</P>
<P>TwoWay 表示既可以从数据源绑定到目标，目标的更改也可以反馈给数据源，使其发生更新。</P>
<P>而 OneTime 是 OneWay 的一种特例，仅加载一次数据。随后数据的变更不会通知绑定目标对象。这样，可以带来更好的性能。</P>
<P>&nbsp;</P>
<P>绑定的语法可以用大括号表示，下面是几个例子：</P>
<P><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana><SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">TextBlock</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Text</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"{Binding Age}"</SPAN> <SPAN style="COLOR: rgb(0,0,255)">/&gt;</SPAN></FONT></FONT></P>
<P>等同于：</P><PRE><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana><SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">TextBlock</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Text</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"{Binding Path=Age}"</SPAN> <SPAN style="COLOR: rgb(0,0,255)">/&gt;</SPAN></FONT></FONT></PRE>
<P>或者显式写出绑定方向：</P><PRE><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana><SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">TextBlock</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Text</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"{Binding Path=Age, Mode=OneWay}"</SPAN> <SPAN style="COLOR: rgb(0,0,255)">/&gt;</SPAN></FONT></FONT></PRE>
<P>&nbsp;</P>
<P>按照数据绑定的语义，默认是 OneWay 的，也就是说如果后台的数据发生变化，前台建立了绑定关系的相关控件也应该发生更新。</P>
<P>比如我们可以将文章 (1) 中提到的数据源改为当前页面的一个私有成员，然后在某个 Button 点击事件中更改其中的值。代码如下：</P><PRE><FONT style="FONT-SIZE: 9pt" face=Verdana>	<SPAN style="COLOR: rgb(0,0,255)">public</SPAN> partial <SPAN style="COLOR: rgb(0,0,255)">class</SPAN> Page : UserControl
	{
		<SPAN style="COLOR: rgb(0,0,255)">private</SPAN> List&lt;Person&gt; persons;
		<SPAN style="COLOR: rgb(0,0,255)">public</SPAN> Page()
		{
			InitializeComponent();

			persons = <SPAN style="COLOR: rgb(0,0,255)">new</SPAN> List&lt;Person&gt;();
			<SPAN style="COLOR: rgb(0,0,255)">for</SPAN>(var i=0; i&lt; 5; i++)
			{
				persons.Add(<SPAN style="COLOR: rgb(0,0,255)">new</SPAN> Person {Name = "<SPAN style="COLOR: rgb(139,0,0)">Person </SPAN>" + i.ToString(), Age = 20 + i});
			}
			list1.DataContext = persons;
		}

		<SPAN style="COLOR: rgb(0,0,255)">private</SPAN> <SPAN style="COLOR: rgb(0,0,255)">void</SPAN> Button_Click(<SPAN style="COLOR: rgb(0,0,255)">object</SPAN> sender, RoutedEventArgs e)
		{
			persons[0].Name = "<SPAN style="COLOR: rgb(139,0,0)">Tom</SPAN>";
		}
	}</FONT></PRE>
<P>但是我们点击 Button 发现 ListBox 里的数据并没有发生变化。这是因为在数据源更新时，并没有发出任何通知。</P>
<P>我们可以让数据源中的对象实现 INotifyPropertyChanged 接口，在绑定的源属性值发生变化时，发出相关的通知信息。</P>
<P>代码如下：</P><PRE><FONT style="FONT-SIZE: 9pt" face=Verdana>	<SPAN style="COLOR: rgb(0,0,255)">public</SPAN> <SPAN style="COLOR: rgb(0,0,255)">class</SPAN> Person: INotifyPropertyChanged
	{
		<SPAN style="COLOR: rgb(0,0,255)">private</SPAN> <SPAN style="COLOR: rgb(0,0,255)">int</SPAN> age;
		<SPAN style="COLOR: rgb(0,0,255)">public</SPAN> <SPAN style="COLOR: rgb(0,0,255)">int</SPAN> Age
		{
			<SPAN style="COLOR: rgb(0,0,255)">get</SPAN>
			{
				<SPAN style="COLOR: rgb(0,0,255)">return</SPAN> age;
			}
			<SPAN style="COLOR: rgb(0,0,255)">set</SPAN>
			{
				age = <SPAN style="COLOR: rgb(0,0,255)">value</SPAN>;
				NotifyPropertyChange("<SPAN style="COLOR: rgb(139,0,0)">Age</SPAN>");
			}
		}

		<SPAN style="COLOR: rgb(0,0,255)">private</SPAN> <SPAN style="COLOR: rgb(0,0,255)">string</SPAN> name;
		<SPAN style="COLOR: rgb(0,0,255)">public</SPAN> <SPAN style="COLOR: rgb(0,0,255)">string</SPAN> Name 
		{
			<SPAN style="COLOR: rgb(0,0,255)">get</SPAN>
			{
				<SPAN style="COLOR: rgb(0,0,255)">return</SPAN> name;
			}
			<SPAN style="COLOR: rgb(0,0,255)">set</SPAN>
			{
				name = <SPAN style="COLOR: rgb(0,0,255)">value</SPAN>;
				NotifyPropertyChange("<SPAN style="COLOR: rgb(139,0,0)">Name</SPAN>");
			}
		}
		<SPAN style="COLOR: rgb(0,0,255)">public</SPAN> <SPAN style="COLOR: rgb(0,0,255)">event</SPAN> PropertyChangedEventHandler PropertyChanged;

		<SPAN style="COLOR: rgb(0,0,255)">private</SPAN> <SPAN style="COLOR: rgb(0,0,255)">void</SPAN> NotifyPropertyChange(<SPAN style="COLOR: rgb(0,0,255)">string</SPAN> propertyName)
		{
			<SPAN style="COLOR: rgb(0,0,255)">if</SPAN>(PropertyChanged != <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>)
			{
				PropertyChanged(<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>, <SPAN style="COLOR: rgb(0,0,255)">new</SPAN> PropertyChangedEventArgs(propertyName));
			}
		}
	}</FONT></PRE>
<P>&nbsp;</P>
<P>这个代码的原理很简单，这里就不解释了。这样以后，点击按钮，前台的 ListBox 中第一条数据的人名就变成了 Tom:</P>
<P><A href="/images/cnblogs_com/RChen/WindowsLiveWriter/Silverlight2_E9A7/listbox3_2.jpg"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=88 alt=listbox3 src="http://www.cnblogs.com/images/cnblogs_com/RChen/WindowsLiveWriter/Silverlight2_E9A7/listbox3_thumb.jpg" width=244 border=0></A> </P>
<P>&nbsp;</P>
<P>俗话说，要知其然，知其所以然。上面的代码说明了在数据源对象中可以设计一个事件通知属性值的变化，并在适当的时候触发之。但是我们并不知道有谁监听了这个事件，并且把这个通知传达到绑定目标对象 (binding target)，也就是 UI.</P>
<P>我们用 Reflector 看看 Silverlight 2 beta 2 的源代码，会发现下列两个关键的类：</P><PRE><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana><SPAN style="COLOR: rgb(0,0,255)">internal</SPAN> <SPAN style="COLOR: rgb(0,0,255)">class</SPAN> BindingExpression : BindingExpressionBase
{
	<SPAN style="COLOR: rgb(0,128,0)">// ...</SPAN>

	<SPAN style="COLOR: rgb(0,128,0)">// 连接到数据源</SPAN>
	<SPAN style="COLOR: rgb(0,0,255)">private</SPAN> <SPAN style="COLOR: rgb(0,0,255)">void</SPAN> ConnectToSource(<SPAN style="COLOR: rgb(0,0,255)">int</SPAN> index)
	{
		<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding._isSealed = <SPAN style="COLOR: rgb(0,0,255)">true</SPAN>;
		<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> (<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding.Path.PathParts == <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>)
		{
			<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._cachedValue = <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._source;
		}
		<SPAN style="COLOR: rgb(0,0,255)">else</SPAN> <SPAN style="COLOR: rgb(0,0,255)">if</SPAN> ((<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourceListeners == <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>) || (index != <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourceListeners.Length))
		{
			<SPAN style="COLOR: rgb(0,0,255)">bool</SPAN> flag = <SPAN style="COLOR: rgb(0,0,255)">false</SPAN>;
			<SPAN style="COLOR: rgb(0,0,255)">try</SPAN>
			{
				<SPAN style="COLOR: rgb(0,0,255)">object</SPAN> source;
				<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> ((<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourceListeners == <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>) &amp;&amp; (<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding.Mode != BindingMode.OneTime))
				{
					<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourceListeners = <SPAN style="COLOR: rgb(0,0,255)">new</SPAN> WeakPropertyChangedListener[<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding.Path.PathParts.Length];
				}
				<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> (index == 0)
				{
					source = <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._source;
				}
				<SPAN style="COLOR: rgb(0,0,255)">else</SPAN>
				{
					source = <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourceListeners[--index].Source;
				}
				<SPAN style="COLOR: rgb(0,0,255)">for</SPAN> (<SPAN style="COLOR: rgb(0,0,255)">int</SPAN> i = index; i &lt; <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding.Path.PathParts.Length; i++)
				{
					<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> (source == <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>)
					{
						flag = <SPAN style="COLOR: rgb(0,0,255)">true</SPAN>;
						<SPAN style="COLOR: rgb(0,0,255)">return</SPAN>;
					}
					<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> ((<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding.Mode != BindingMode.OneTime) &amp;&amp; (<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourceListeners[i] == <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>))
					{
						<SPAN style="COLOR: rgb(0,128,0)">// 这里尝试创建源对象的属性变更监听器 (A)</SPAN>
						<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourceListeners[i] = WeakPropertyChangedListener.CreateIfNecessary(source, <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>);
					}
					<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourcePropertyInfo = source.GetType().GetProperty(<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding.Path.PathParts[i]);
					<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._leafSourceObject = source;
					<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> (<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourcePropertyInfo == <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>)
					{
						TraceBindingError("<SPAN style="COLOR: rgb(139,0,0)">The path '</SPAN>" + <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding._path.Path + "<SPAN style="COLOR: rgb(139,0,0)">' is invalid</SPAN>");
						<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._leafSourceObject = <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>;
						flag = <SPAN style="COLOR: rgb(0,0,255)">true</SPAN>;
						<SPAN style="COLOR: rgb(0,0,255)">return</SPAN>;
					}
					<SPAN style="COLOR: rgb(0,0,255)">try</SPAN>
					{
						source = <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourcePropertyInfo.GetValue(source, <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>);
					}
					<SPAN style="COLOR: rgb(0,0,255)">catch</SPAN> (TargetInvocationException)
					{
						TraceBindingError("<SPAN style="COLOR: rgb(139,0,0)">Could not connect to '</SPAN>" + <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding._path.Path + "<SPAN style="COLOR: rgb(139,0,0)">'</SPAN>");
						<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._leafSourceObject = <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>;
						<SPAN style="COLOR: rgb(0,0,255)">return</SPAN>;
					}
				}
				<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> ((<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._binding.Mode == BindingMode.OneTime) || (<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourceListeners[<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourceListeners.Length - 1] == <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>))
				{
					<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._cachedValue = source;
				}
				flag = <SPAN style="COLOR: rgb(0,0,255)">true</SPAN>;
			}
			<SPAN style="COLOR: rgb(0,0,255)">finally</SPAN>
			{
				<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> (!flag)
				{
					<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>.DisconnectFromSource(index);
					<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._sourcePropertyInfo = <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>;
					<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._leafSourceObject = <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>;
				}
			}
		}
	}
}


<SPAN style="COLOR: rgb(0,0,255)">internal</SPAN> <SPAN style="COLOR: rgb(0,0,255)">class</SPAN> WeakPropertyChangedListener
{
	<SPAN style="COLOR: rgb(0,128,0)">// ...</SPAN>

	<SPAN style="COLOR: rgb(0,128,0)">// 被 (A) 处代码调用 (B)</SPAN>
	<SPAN style="COLOR: rgb(0,0,255)">internal</SPAN> <SPAN style="COLOR: rgb(0,0,255)">static</SPAN> WeakPropertyChangedListener CreateIfNecessary(<SPAN style="COLOR: rgb(0,0,255)">object</SPAN> source, BindingExpression bindingExpression)
	{
		<SPAN style="COLOR: rgb(0,128,0)">// 查看数据源是否实现了 INotifyPropertyChanged 接口</SPAN>
		INotifyPropertyChanged notify = source <SPAN style="COLOR: rgb(0,0,255)">as</SPAN> INotifyPropertyChanged;
		<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> (notify != <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>)
		{
			<SPAN style="COLOR: rgb(0,128,0)">// 如果有，创建一个监听器，调用 (C)</SPAN>
			<SPAN style="COLOR: rgb(0,0,255)">return</SPAN> <SPAN style="COLOR: rgb(0,0,255)">new</SPAN> WeakPropertyChangedListener(notify, bindingExpression);
		}
		<SPAN style="COLOR: rgb(0,0,255)">return</SPAN> <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>;
	}

	<SPAN style="COLOR: rgb(0,128,0)">// 构造函数 (C)</SPAN>
	 <SPAN style="COLOR: rgb(0,0,255)">private</SPAN> WeakPropertyChangedListener(INotifyPropertyChanged notify, BindingExpression bindingExpression)
	{
		<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._notifyPropertyChanged = notify;
		<SPAN style="COLOR: rgb(0,128,0)">// 这里注册事件的回调函数，以便在属性变化时获得通知（调用 D）</SPAN>
		notify.PropertyChanged += <SPAN style="COLOR: rgb(0,0,255)">new</SPAN> PropertyChangedEventHandler(<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>.PropertyChangedCallback);
		<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._weakBindingExpression = <SPAN style="COLOR: rgb(0,0,255)">new</SPAN> WeakReference(bindingExpression);
	}

	<SPAN style="COLOR: rgb(0,128,0)">// 回调函数 (D)</SPAN>
	<SPAN style="COLOR: rgb(0,0,255)">private</SPAN> <SPAN style="COLOR: rgb(0,0,255)">void</SPAN> PropertyChangedCallback(<SPAN style="COLOR: rgb(0,0,255)">object</SPAN> sender, PropertyChangedEventArgs args)
	{
		BindingExpression target = <SPAN style="COLOR: rgb(0,0,255)">this</SPAN>._weakBindingExpression.Target <SPAN style="COLOR: rgb(0,0,255)">as</SPAN> BindingExpression;
		<SPAN style="COLOR: rgb(0,128,0)">// 这里触发绑定目标对象的更新 (E)</SPAN>
		<SPAN style="COLOR: rgb(0,0,255)">if</SPAN> (target != <SPAN style="COLOR: rgb(0,0,255)">null</SPAN>)
		{
			target.SourcePropertyChanged(sender, args);
		}
		<SPAN style="COLOR: rgb(0,0,255)">else</SPAN>
		{
			<SPAN style="COLOR: rgb(0,0,255)">this</SPAN>.Disconnect();
		}
	}

}</FONT></FONT></PRE>
<P>由上述代码跟踪可以看到整个调用流程(A -&gt; B -&gt; C -&gt; D)：</P>
<P>&nbsp;</P>
<P>BindingExpression.ConnectToSource()</P>
<P>-&gt; WeakPropertyChangedListener.ctor()</P>
<P>-&gt; WeakPropertyChangedListener.PropertyChangedCallback()</P>
<P>-&gt; BindingExpression.SourcePropertyChanged()</P>
<P>&nbsp;</P>
<P>在 BindingExpression 中连接数据源时，就判断其是否实现了 INotifyPropertyChanged 接口，如果实现了，则注册一个回调函数。</P>
<P>在数据源发生变化时，将触发这个回调函数，在这个函数中调用到 BindingExpression 的 SourcePropertyChanged() 函数去更新目标对象。</P>
<P>这样就实现了一个 source -&gt; target 绑定的数据更新触发机制。</P><img src ="http://www.cnblogs.com/RChen/aggbug/1235816.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41286/" target="_blank">[新闻]巨人与51.COM本月26日互通帐号</a>]]></description></item><item><title>Silverlight 数据绑定 (1)：怎样实现数据绑定</title><link>http://www.cnblogs.com/RChen/archive/2008/07/03/1235039.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Thu, 03 Jul 2008 11:43:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/03/1235039.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1235039.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/03/1235039.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1235039.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1235039.html</trackback:ping><description><![CDATA[<P>一个数据绑定可以通过 Binding 对象来描述，其中包含数据源，要绑定的属性路径(Path)，目标，目标属性等。<BR>其中目标属性必须是依赖属性(DependencyProperty)。<BR>为了说明方便，首先定义一个数据类：<BR><BR></P><PRE><FONT style="FONT-SIZE: 9pt" face=Verdana>    <SPAN style="COLOR: rgb(0,0,255)">public</SPAN> <SPAN style="COLOR: rgb(0,0,255)">class</SPAN> Person
    {
        <SPAN style="COLOR: rgb(0,0,255)">public</SPAN> <SPAN style="COLOR: rgb(0,0,255)">int</SPAN> Age { <SPAN style="COLOR: rgb(0,0,255)">get</SPAN>; <SPAN style="COLOR: rgb(0,0,255)">set</SPAN>; }
        <SPAN style="COLOR: rgb(0,0,255)">public</SPAN> <SPAN style="COLOR: rgb(0,0,255)">string</SPAN> Name { <SPAN style="COLOR: rgb(0,0,255)">get</SPAN>; <SPAN style="COLOR: rgb(0,0,255)">set</SPAN>; }
    }</FONT><BR><BR><BR></PRE><PRE>例子1：</PRE><PRE><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana>        <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN> <SPAN style="COLOR: rgb(255,0,0)">x</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">Name</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"list1"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
            
        <SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN></FONT></FONT></PRE>
<P>&nbsp;</P><PRE><FONT style="FONT-SIZE: 9pt" face=Verdana>    <SPAN style="COLOR: rgb(0,0,255)">public</SPAN> partial <SPAN style="COLOR: rgb(0,0,255)">class</SPAN> Page : UserControl
    {
        <SPAN style="COLOR: rgb(0,0,255)">public</SPAN> Page()
        {
            InitializeComponent();

            var persons = <SPAN style="COLOR: rgb(0,0,255)">new</SPAN> List&lt;Person&gt;();
            <SPAN style="COLOR: rgb(0,0,255)">for</SPAN>(var i=0; i&lt; 5; i++)
            {
                persons.Add(<SPAN style="COLOR: rgb(0,0,255)">new</SPAN> Person {Name = "<SPAN style="COLOR: rgb(139,0,0)">Person </SPAN>" + i.ToString(), Age = 20 + i});
            }
            list1.DataContext = persons;
        }
    }</FONT></PRE><PRE>这里仅指定了 list1 的 DataContext 属性，运行后发现页面没有显示。</PRE><PRE>如果在页面里改一改：</PRE><PRE><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana>        <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN> <SPAN style="COLOR: rgb(255,0,0)">x</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">Name</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"list1"</SPAN> <SPAN style="COLOR: rgb(255,0,0)">ItemsSource</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"{Binding}"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
            
        <SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN></FONT></FONT></PRE>
<P>会发现绑定成功。但是数据项显示为默认的 Person 对象 ToString() 后的表示，不太友好。如下图：</P>
<P><A href="/images/cnblogs_com/RChen/WindowsLiveWriter/Silverlight1_11500/listbox1_2.jpg"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=95 alt=listbox1 src="http://www.cnblogs.com/images/cnblogs_com/RChen/WindowsLiveWriter/Silverlight1_11500/listbox1_thumb.jpg" width=244 border=0></A> </P>
<P>或者，也可以将后台代码改成：</P><PRE><FONT style="FONT-SIZE: 9pt" face=Verdana>list1.ItemsSource = persons;</FONT></PRE>
<P>而页面 markup 仍然是：</P><PRE><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana>        <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN> <SPAN style="COLOR: rgb(255,0,0)">x</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">Name</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"list1"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
            
        <SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN></FONT></FONT></PRE>
<P>这样也能绑定成功。<BR>这里的原因在于：ListBox 通过 ItemsSource 里的数据去填充数据项，所以直接给这个属性赋值是可以的。<BR>或者，通过空绑定语法 {Binding}，指定 ItemsSource 属性绑定为数据源的对象本身（未指定绑定路径）。而数据源就是通过 DataContext 获得的，并且这个属性的数据可以从父对象继承下来。<BR>下面给 ListBox 指定列表项的数据模板，让它显示的好看一点：</P><PRE><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana>        <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN> <SPAN style="COLOR: rgb(255,0,0)">x</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">Name</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"list1"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
            <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox.ItemTemplate</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
                <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">DataTemplate</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
                    <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">StackPanel</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Orientation</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"Horizontal"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
                        <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">TextBlock</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Text</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"{Binding Age}"</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Margin</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"20,0"</SPAN> <SPAN style="COLOR: rgb(0,0,255)">/&gt;</SPAN>
                        <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">TextBlock</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Text</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"{Binding Name}"</SPAN> <SPAN style="COLOR: rgb(0,0,255)">/&gt;</SPAN>
                    <SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">StackPanel</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
                <SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">DataTemplate</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
            <SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox.ItemTemplate</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
        <SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN></FONT></FONT></PRE>显示如下：<BR><BR><A href="/images/cnblogs_com/RChen/WindowsLiveWriter/Silverlight1_11500/listbox2_2.jpg"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=106 alt=listbox2 src="http://www.cnblogs.com/images/cnblogs_com/RChen/WindowsLiveWriter/Silverlight1_11500/listbox2_thumb.jpg" width=244 border=0></A> <BR>
<P>还可以将 DataTemplate 定义到 App 的 Resource 里去，以便于重用。</P>
<P>App.xaml:</P><PRE><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana><SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">Application</SPAN> <SPAN style="COLOR: rgb(255,0,0)">xmlns</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</SPAN>
             <SPAN style="COLOR: rgb(255,0,0)">xmlns</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">x</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"http://schemas.microsoft.com/winfx/2006/xaml"</SPAN> 
             <SPAN style="COLOR: rgb(255,0,0)">x</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">Class</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"SilverlightTestApp.App"</SPAN>
             <SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
    <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">Application.Resources</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
		<SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">DataTemplate</SPAN> <SPAN style="COLOR: rgb(255,0,0)">x</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">Key</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"ListBoxDataTemplate"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
			<SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">StackPanel</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Orientation</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"Horizontal"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
				<SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">TextBlock</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Text</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"{Binding Age}"</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Margin</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"20,0"</SPAN> <SPAN style="COLOR: rgb(0,0,255)">/&gt;</SPAN>
				<SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">TextBlock</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Text</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"{Binding Name}"</SPAN> <SPAN style="COLOR: rgb(0,0,255)">/&gt;</SPAN>
			<SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">StackPanel</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
		<SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">DataTemplate</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
	<SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">Application.Resources</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
<SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">Application</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN></FONT></FONT>
</PRE>
<P>&nbsp;</P>
<P>Page.xaml:</P><PRE><FONT style="FONT-SIZE: 9pt"><FONT face=Verdana><SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">UserControl</SPAN> <SPAN style="COLOR: rgb(255,0,0)">x</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">Class</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"SilverlightTestApp.Page"</SPAN>
    <SPAN style="COLOR: rgb(255,0,0)">xmlns</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</SPAN> 
    <SPAN style="COLOR: rgb(255,0,0)">xmlns</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">x</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"http://schemas.microsoft.com/winfx/2006/xaml"</SPAN> 
    <SPAN style="COLOR: rgb(255,0,0)">Width</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"400"</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Height</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"300"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
    <SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">Grid</SPAN> <SPAN style="COLOR: rgb(255,0,0)">x</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">Name</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"LayoutRoot"</SPAN> <SPAN style="COLOR: rgb(255,0,0)">Background</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"White"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
		<SPAN style="COLOR: rgb(0,0,255)">&lt;</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN> <SPAN style="COLOR: rgb(255,0,0)">x</SPAN>:<SPAN style="COLOR: rgb(255,0,0)">Name</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"list1"</SPAN> <SPAN style="COLOR: rgb(255,0,0)">ItemTemplate</SPAN>=<SPAN style="COLOR: rgb(0,0,255)">"{StaticResource ListBoxDataTemplate}"</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
		<SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">ListBox</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>
	<SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">Grid</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN>	
<SPAN style="COLOR: rgb(0,0,255)">&lt;/</SPAN><SPAN style="COLOR: rgb(128,0,0)">UserControl</SPAN><SPAN style="COLOR: rgb(0,0,255)">&gt;</SPAN></FONT></FONT>
</PRE>
<P>&nbsp;</P>
<P>运行后效果一样。</P><img src ="http://www.cnblogs.com/RChen/aggbug/1235039.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41285/" target="_blank">[新闻]FEEDSKY和BLOGBUS的出路</a>]]></description></item></channel></rss>