﻿<?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>Focusd on Silverlight</description><language>zh-cn</language><lastBuildDate>Thu, 28 Aug 2008 12:01:07 GMT</lastBuildDate><pubDate>Thu, 28 Aug 2008 12:01:07 GMT</pubDate><ttl>60</ttl><item><title>判断句子是不是魔法咒语的算法</title><link>http://www.cnblogs.com/RChen/archive/2008/08/21/1272667.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Wed, 20 Aug 2008 17:27:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/08/21/1272667.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1272667.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/08/21/1272667.html#Feedback</comments><slash:comments>24</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1272667.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1272667.html</trackback:ping><description><![CDATA[javaeye 上看到一个帖子讲动态规划算法的：<br><a href="http://www.javaeye.com/topic/204976?page=1">http://www.javaeye.com/topic/204976?page=1</a><br><br>其中提出了一个题目：判断句子是不是魔法咒语。<br>描述如下：<br><br>"话说有个魔法字典，其中记录了一些魔力单词（字符串），如果一个句子（也是字符串）可以被完全分解为若干魔力单词的拼接，那么这个句子就是一条咒语。假设
我们可以用常数时间查询魔力字典是否包含一个特定的单词，那么现在给你一个句子，让你写一个程序判断这个句子是否一条咒语。用动态规划可以解哦。"<br><br>其中跟贴的有人说到需要先列出“状态转移方程”<span style="color: red;"></span>，我不太懂，不过觉得这个问题倒是可以用回溯法尝试一下。<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, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">coding:&nbsp;utf-8</span><span style="color: rgb(0, 128, 0);"><br>#</span><span style="color: rgb(0, 128, 0);">2008-8-21,&nbsp;Neil&nbsp;Chen</span><span style="color: rgb(0, 128, 0);"><br>#</span><span style="color: rgb(0, 128, 0);">&nbsp;判断一个句子是否为咒语（由魔法词组成）</span><span style="color: rgb(0, 128, 0);"><br>#</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);"><br></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);">magic_words&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, 0);">'</span><span style="color: rgb(128, 0, 0);">m</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">foo</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">bar</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">boo</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">barr</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">jac</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">j</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">c</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">]<br><br></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, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;is_magic_word(word):<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;word&nbsp;</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">&nbsp;magic_words<br><br></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, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;is_spell(sentence):<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;最终如能成功分割为魔法单词，则句子中会出现&nbsp;n&nbsp;个分隔点，</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&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;&nbsp;split_points&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, 0);">1</span><span style="color: rgb(0, 0, 0);">]<br>&nbsp;&nbsp;&nbsp;&nbsp;n&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;len(sentence)<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;True:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;判断最后两个分隔点之间的单词是否为魔力单词，否则将该位置增加1，继续尝试</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is_magic&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;False<br>&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;split_points[</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">]&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;=</span><span style="color: rgb(0, 0, 0);">&nbsp;n:<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;len(split_points)&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, 0);">1</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;start&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">else</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;start&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;split_points[</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">2</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, 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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;word&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;sentence[start&nbsp;:&nbsp;split_points[</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">]]&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);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;is_magic_word(word):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is_magic&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;True<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);">break</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);">else</span><span style="color: rgb(0, 0, 0);">:&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;split_points[</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</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);">&nbsp;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;is_magic:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&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;split_points[</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</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);">&nbsp;n:<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);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">else</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;split_points.append(split_points[</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</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);">&nbsp;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">else</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, 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;&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;len(split_points)&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, 0);">1</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);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">else</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;split_points.pop()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;split_points[</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</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);">&nbsp;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"><br><br><br></span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">================&nbsp;测试代码&nbsp;======================</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">__name__</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);">&nbsp;</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">__main__</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;is_magic_word(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">foo</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;True</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;is_magic_word(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">fo</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;False</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;is_spell(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">morning</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;False</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;is_spell(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">hello</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;False</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;is_spell(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">foo</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;True</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;is_spell(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">bar</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;True</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;is_spell(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">barfoombarmjac</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;True</span><span style="color: rgb(0, 128, 0);"><br></span></div><br><br>以上代码已经实现了这个算法。（不过有个小小的问题，如果字符串里含有中文，则不能正确判断，这是因为 python 中 len() 函数判断中文为双字节造成的，等有时间再改进这个）。<br><br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1272667.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41940/" target="_blank">[新闻]惠普139亿美元完成对EDS的收购</a>]]></description></item><item><title>斐波纳契数列非递归算法</title><link>http://www.cnblogs.com/RChen/archive/2008/08/20/1272635.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Wed, 20 Aug 2008 15:20:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/08/20/1272635.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1272635.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/08/20/1272635.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1272635.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1272635.html</trackback:ping><description><![CDATA[fibonacci 数列定义：<br><br>n = 1,2 时，fib(n) = 1<br>n &gt; 2 时，fib(n) = fib(n-2) + fib(n-1)<br><br>如果用递归计算则包含非常多的重复计算量，因此不可考虑。<br>换一个思路，只要从 f(1) 计算到 f(n-1)，那么这个过程是不会有重复计算的。<br>很多算法用了数组来保存 f(1)到 f(n) 的值，如果 n 很大，则这个空间开销会很大，好处是在需要计算很多个 f(n) 的时候可以利用“缓存”。<br>如果仅需要计算一个 f(n) 值，就没必要分配这个数组。可以两个临时变量搞定，分别保存 f(n-2),f(n-1)的值。<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, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">coding:&nbsp;utf-8</span><span style="color: rgb(0, 128, 0);"><br>#</span><span style="color: rgb(0, 128, 0);">2008-8-20&nbsp;Neil&nbsp;Chen</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;fib(n):<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;n&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">3</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);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;a&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, 0);">1</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;b&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, 0);">1</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">&nbsp;range(</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">,&nbsp;n&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, 0);">1</span><span style="color: rgb(0, 0, 0);">):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;a&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;b<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;b&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">&nbsp;a<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;a&nbsp;</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">&nbsp;b<br><br></span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;fib(</span><span style="color: rgb(0, 0, 0);">256</span><span style="color: rgb(0, 0, 0);">)<br></span></div><br>这个算法的空间复杂度为 O(1).<br>时间复杂度为 O(n).<br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1272635.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41939/" target="_blank">[新闻]搜狗五笔输入法发布</a>]]></description></item><item><title>提交了 VS 2008 sp1 对 Linq to SQL 的 xml 字段类型支持的一个 bug</title><link>http://www.cnblogs.com/RChen/archive/2008/08/12/1266375.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Tue, 12 Aug 2008 14:06:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/08/12/1266375.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1266375.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/08/12/1266375.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1266375.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1266375.html</trackback:ping><description><![CDATA[<A href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361451">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361451</A><BR><BR>Before vs 2008 sp1, I have a property who's type is XElement in Linq to SQL designer.<BR>I set the 'Server Data Type' value in property grid to 'xml', and it works fine.<BR><BR>However, after installed the sp, it doesn't compile, here is the error message:<BR>---------<BR>Error&nbsp;&nbsp;&nbsp;&nbsp;27&nbsp;&nbsp;&nbsp;&nbsp;DBML1005: Mapping between DbType 'xml' and Type 'System.Xml.Linq.XElement' in Column 'Data' of Type 'Sale' is not supported.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;<BR>---------<BR><BR>On the other hand, if I create a new table in SQL Server 2005 with a 'xml' column type, then drag and drop the table from Server Explorer to the dbml designer interface, the entity generated also maps to 'XElement' automatically, and has a 'Server Data Type' of 'Xml', it doesn't compile either.<BR><BR>So I think this is an bug, if there are any walk arounds please tell me. thanks very much.<BR><BR>The third way, if I leave the 'Server Data Type' property to blank, and set the column type in SQL Server 2005 to 'xml' manulely, the project compiles successfully. However, the 'CreateDatabase' method of the DataContext will fail.<BR>here is the code:<BR>===<BR>var db = new testDataContext();<BR>if (! db.DatabaseExists())<BR>&nbsp;&nbsp;&nbsp;&nbsp;db.CreateDatabase();<BR>===<BR>This will produce the following error:<BR>"无法确定“System.Xml.Linq.XElement”的 SQL 类型。"<BR>(in English maybe it's identical to "The SQL type of 'System.Xml.Linq.XElement' is not sure'.)<BR><BR>This bug makes me very hard to automatically generate database from Linq to SQL side, or the reverse way, both direction need some manual adjustments.<BR><BR><img src ="http://www.cnblogs.com/RChen/aggbug/1266375.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41938/" target="_blank">[新闻]新学年开始 大学生适用的十大互联网应用</a>]]></description></item><item><title>如何在 vista 的 iis 7 上面配置 asp.net 1.1 开发环境</title><link>http://www.cnblogs.com/RChen/archive/2008/08/08/1263400.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Fri, 08 Aug 2008 01:03:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/08/08/1263400.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1263400.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/08/08/1263400.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1263400.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1263400.html</trackback:ping><description><![CDATA[在 vista 上配置 asp.net 1.1，问题层出不穷。主要问题在于 vs 2003 比较依赖于 IIS.<br><br>参考：<br><a href="http://www.cublog.cn/u/884/showart.php?id=261667">http://www.cublog.cn/u/884/showart.php?id=261667</a><br><a href="/david-chan/archive/2007/07/13/817364.html">http://www.cnblogs.com/david-chan/archive/2007/07/13/817364.html</a><br><a href="http://blogs.iis.net/brian-murphy-booth/archive/2007/03/09/how-to-setup-asp-net-v1-1-visual-studio-net-2003-projects-on-iis7-vista.aspx">http://blogs.iis.net/brian-murphy-booth/archive/2007/03/09/how-to-setup-asp-net-v1-1-visual-studio-net-2003-projects-on-iis7-vista.aspx</a><br><a href="http://blogs.iis.net/bills/archive/2008/06/02/installing-asp-net-1-1-with-iis7-on-vista-and-windows-2008.aspx">http://blogs.iis.net/bills/archive/2008/06/02/installing-asp-net-1-1-with-iis7-on-vista-and-windows-2008.aspx</a><br><br>安装步骤：<br><br>1. 必须安装 .net framework 1.1 sp1，否则会报错。<br>2. 打开 iis6 管理兼容性。（在程序与功能/windows功能里）<br>3. 注册 iis 脚本。<br>&nbsp;&nbsp; 用管理员权限打开 vs 03 的 console. 然后执行：<br>&nbsp;&nbsp; aspnet_regiis.exe -ir -enable<br>&nbsp;&nbsp; 其中 -r 表示不改变现有脚本映射。<br>&nbsp;&nbsp; -enable 是打开 "ISAPI 和 CGI 限制" 为 Allow. 这个也可以在 iis 里设置。<br>4. iis 管理器中，选择“计算机名”，"ISAPI和CGI限制”，确认 asp.net 1.1 是 Allow 状态。<br>5. 设置默认应用程序池为 1.1 的。<br>&nbsp;&nbsp; （否则的话就要 vs 里建好网站再改应用程序池设置）<br><br>6. 最后一点最重要。在 1.1 的 machine.config 里加一个节处理器的配置如下：<br><br>&lt;section name="system.webServer" type="System.Configuration.IgnoreSectionHandler, <br>&nbsp;&nbsp;&nbsp; System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt; <br><br>加在 &lt;/configSections&gt; 结束前即可。<br>否则会报不能识别 &lt;webServer&gt; 的节。<br><br>machine.config 的位置在 %windir%\Microsoft.NET\Framework\v1.1.4322\config\machine.config<br><br>之后还发现一些 vs 03 不能调试的错误。记录如下：<br><br><br>---------------------------<br>Microsoft Development Environment<br>---------------------------<br>Error while trying to run project: Unable to start debugging on the web server. You do not have permission to debug the application. The URL for this project is in the Internet zone. Click Help for more information.<br>---------------------------<br>确定&nbsp;&nbsp; 帮助&nbsp;&nbsp; <br>---------------------------<br><br>解决办法：在 IE 选项的安全设置里，将 http://localhost 加入本地站点（默认有一个 http://127.0.0.1，<br>其实是一样的，但是不知道为啥不能识别）。<br><br><br>---------------------------<br>Microsoft Development Environment<br>---------------------------<br>Error while trying to run project: Unable to start debugging on the web server. Debugging failed because integrated Windows authentication is not enabled. Click Help for more information.<br>---------------------------<br>确定&nbsp;&nbsp; 帮助&nbsp;&nbsp; <br>---------------------------<br><br>解决办法：iis -&gt; 选中站点 -&gt; 身份验证<br>启用 "Windows 身份验证"<br><br><br><br><br><br><br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1263400.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41937/" target="_blank">[新闻]Google拟在9月发布自有浏览器 或采用火狐内核</a>]]></description></item><item><title>利用 Xml Literal 功能复制一段 Xml</title><link>http://www.cnblogs.com/RChen/archive/2008/08/02/1258980.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Sat, 02 Aug 2008 13:17:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/08/02/1258980.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1258980.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/08/02/1258980.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1258980.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1258980.html</trackback:ping><description><![CDATA[<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);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">Function</span><span style="color: rgb(0, 0, 0);">&nbsp;CopyXml(</span><span style="color: rgb(0, 0, 255);">ByVal</span><span style="color: rgb(0, 0, 0);">&nbsp;element&nbsp;</span><span style="color: rgb(0, 0, 255);">As</span><span style="color: rgb(0, 0, 0);">&nbsp;XElement)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">Dim</span><span style="color: rgb(0, 0, 0);">&nbsp;xml&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, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;element.Name&nbsp;%</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;element.Attributes&nbsp;%</span><span style="color: rgb(0, 0, 0);">&gt;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;From&nbsp;x&nbsp;</span><span style="color: rgb(0, 0, 255);">In</span><span style="color: rgb(0, 0, 0);">&nbsp;element.Nodes&nbsp;_<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;&nbsp;&nbsp;Where&nbsp;x.NodeType&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Xml.XmlNodeType.Element&nbsp;_<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;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">Select</span><span style="color: rgb(0, 0, 0);">&nbsp;x&nbsp;%</span><span style="color: rgb(0, 0, 0);">&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;From&nbsp;x&nbsp;</span><span style="color: rgb(0, 0, 255);">In</span><span style="color: rgb(0, 0, 0);">&nbsp;element.Elements&nbsp;%</span><span style="color: rgb(0, 0, 0);">&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;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;/&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);">Return</span><span style="color: rgb(0, 0, 0);">&nbsp;xml<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">End&nbsp;Function</span></div><br><br>这个例子的目的是练习如何进行 Xml 文档转换，以替代以前 xslt 的功能。<br>在 &lt;%= %&gt; 中可以嵌入递归调用，这样就能做任意层次的文档转换，xslt 可以完全扔掉了。<br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1258980.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41936/" target="_blank">[新闻]微软正在构思将Wi-Fi带入汽车</a>]]></description></item><item><title>[Silverlight] 用 IronPython 创建和调用用户控件</title><link>http://www.cnblogs.com/RChen/archive/2008/08/01/1258011.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Fri, 01 Aug 2008 03:12:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/08/01/1258011.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1258011.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/08/01/1258011.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1258011.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1258011.html</trackback:ping><description><![CDATA[关于如何用动态语言跑 Silverlight 就不说了，可以参考代振军的<b><a href="/daizhj/archive/2008/07/16/1244420.html" target="_blank">帖子</a></b>。但是很多教程都没有提到怎样才能分模块开发，在介绍完一个 app 后就结束了。现在来看一下如何实现用户控件的动态加载，其实也很简单。<br><br>关键是用到了 Application.LoadComponent 这个方法，他可以加载指定的 xaml，并转换成某个类型的对象。为了减少重复工作，我做了一个简单的基类，叫做 UserControlBase. 整个例子的目录结构如下：<br><br>/default.htm<br>/app<br>&nbsp;&nbsp; app.xaml<br>&nbsp;&nbsp; app.py<br>&nbsp;&nbsp; usercontrol_base.py<br>&nbsp;&nbsp; control1.xaml<br>&nbsp;&nbsp; control1.py<br><br>其中 control1.xaml 和 control1.py 就类似于 C# 里的 code behind 方式，不过这里的关联是要自己代码里来指定的。<br>例子的运行效果如下：<br><br><img src="http://www.cnblogs.com/images/cnblogs_com/rchen/ipy_uc.png" alt="ipy_uc.png" width="503" border="0" height="448"><br><br>点击一下 “加载用户控件”，子控件就会加载进来。而在子控件中也能独立处理自己的事件。<br><br>下面是代码：<br><br><b>app.xaml</b><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(128, 0, 0);">UserControl&nbsp;</span><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/client/2007"</span><span style="color: rgb(255, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;xmlns:x</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/winfx/2006/xaml"</span><span style="color: rgb(255, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;x:Class</span><span style="color: rgb(0, 0, 255);">="System.Windows.Controls.UserControl"</span><span style="color: rgb(255, 0, 0);">&nbsp;Width</span><span style="color: rgb(0, 0, 255);">="400"</span><span style="color: rgb(255, 0, 0);">&nbsp;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, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid&nbsp;</span><span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="LayoutRoot"</span><span style="color: rgb(255, 0, 0);">&nbsp;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, 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);">StackPanel&nbsp;</span><span style="color: rgb(255, 0, 0);">Orientation</span><span style="color: rgb(0, 0, 255);">="Vertical"</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);">TextBlock</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">这是主页面</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">TextBlock</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);">Button&nbsp;</span><span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="btnLoad"</span><span style="color: rgb(255, 0, 0);">&nbsp;Content</span><span style="color: rgb(0, 0, 255);">="加载用户控件"</span><span style="color: rgb(255, 0, 0);">&nbsp;</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);">Border&nbsp;</span><span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="placeHolder"</span><span style="color: rgb(255, 0, 0);">&nbsp;Width</span><span style="color: rgb(0, 0, 255);">="400"</span><span style="color: rgb(255, 0, 0);">&nbsp;Height</span><span style="color: rgb(0, 0, 255);">="300"</span><span style="color: rgb(255, 0, 0);">&nbsp;Margin</span><span style="color: rgb(0, 0, 255);">="0,20,0,0"</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;<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);">Border</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);">StackPanel</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);">Grid</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);">UserControl</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br></span></div><br><b>app.py</b><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, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">coding:&nbsp;utf-8</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);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;Microsoft.Scripting.Silverlight&nbsp;</span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;DynamicApplication<br></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Windows.Controls&nbsp;</span><span style="color: rgb(0, 0, 255);">import</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);"><br></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Windows.Browser&nbsp;</span><span style="color: rgb(0, 0, 255);">import</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);"><br><br></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;App:<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">__init__</span><span style="color: rgb(0, 0, 0);">(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.scene&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;DynamicApplication.Current.LoadRootVisual(UserControl(),&nbsp;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">app.xaml</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;start(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.scene.btnLoad.Click&nbsp;</span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);">&nbsp;self.btnLoad_Click<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;btnLoad_Click(self,&nbsp;sender,&nbsp;eventArgs):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;control1&nbsp;</span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;Control1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uc&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Control1()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.scene.placeHolder.Child&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;uc.page<br><br>App().start()<br></span></div><br><br><b>usercontrol_base.py</b><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, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">coding:&nbsp;utf-8</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);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;Microsoft.Scripting.Silverlight&nbsp;</span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;DynamicApplication<br></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Windows.Controls&nbsp;</span><span style="color: rgb(0, 0, 255);">import</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);"><br></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Windows.Browser&nbsp;</span><span style="color: rgb(0, 0, 255);">import</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);"><br><br></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, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;UserControlBase:<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">__init__</span><span style="color: rgb(0, 0, 0);">(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.page&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;UserControl()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;加载&nbsp;Xaml</span><span style="color: rgb(0, 128, 0);"><br></span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DynamicApplication.Current.LoadComponent(self.page,&nbsp;self.get_xaml_path())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.OnInit()<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;OnInit(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">pass</span><span style="color: rgb(0, 0, 0);"><br></span></div><br><br><b>control1.xaml</b><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(128, 0, 0);">UserControl&nbsp;</span><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/client/2007"</span><span style="color: rgb(255, 0, 0);"><br>&nbsp;xmlns:x</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/winfx/2006/xaml"</span><span style="color: rgb(255, 0, 0);"><br>&nbsp;x:Class</span><span style="color: rgb(0, 0, 255);">="System.Windows.Controls.UserControl"</span><span style="color: rgb(255, 0, 0);">&nbsp;Width</span><span style="color: rgb(0, 0, 255);">="400"</span><span style="color: rgb(255, 0, 0);">&nbsp;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, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid&nbsp;</span><span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="LayoutRoot"</span><span style="color: rgb(255, 0, 0);">&nbsp;Background</span><span style="color: rgb(0, 0, 255);">="#ccccff"</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);">StackPanel&nbsp;</span><span style="color: rgb(255, 0, 0);">Orientation</span><span style="color: rgb(0, 0, 255);">="Vertical"</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);">TextBlock&nbsp;</span><span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="text1"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">这是子页面</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">TextBlock</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);">Button&nbsp;</span><span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="button1"</span><span style="color: rgb(255, 0, 0);">&nbsp;Content</span><span style="color: rgb(0, 0, 255);">="test"</span><span style="color: rgb(255, 0, 0);">&nbsp;</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);">StackPanel</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);">Grid</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);">UserControl</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br></span></div><br><br><b>control1.py</b><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, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">coding:&nbsp;utf-8</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);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;System<br></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Windows&nbsp;</span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;Application<br></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;Microsoft.Scripting.Silverlight&nbsp;</span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;DynamicApplication<br></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Windows.Controls&nbsp;</span><span style="color: rgb(0, 0, 255);">import</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);"><br></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;System.Windows.Browser&nbsp;</span><span style="color: rgb(0, 0, 255);">import</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);"><br></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);">&nbsp;usercontrol_base&nbsp;</span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;UserControlBase<br><br></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;Control1(UserControlBase):<br>&nbsp;&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;&nbsp;</span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;get_xaml_path(self):<br>&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;</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">control1.xaml</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&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;&nbsp;</span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;OnInit(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.page.button1.Click&nbsp;</span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);">&nbsp;self.button1_Click<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);">&nbsp;button1_Click(self,&nbsp;sender,&nbsp;eventArgs):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HtmlPage.Window.Alert(self.page.text1.Text)<br></span></div><br><br>这里有一点值得注意，就是编写的 xaml 文件中如果要包含中文，则最好保存为 UTF-8 格式，否则文件加载时会报错。<br><br><br><br><br><br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1258011.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41935/" target="_blank">[新闻]对比测试：IE8 Beta 2 VS Firefox 3.0.1</a>]]></description></item><item><title>[Silverlight] Nikhil Kothari 的动画框架 Glitz（摘要）</title><link>http://www.cnblogs.com/RChen/archive/2008/07/31/1257034.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Thu, 31 Jul 2008 01:53:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/31/1257034.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1257034.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/31/1257034.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1257034.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1257034.html</trackback:ping><description><![CDATA[原文地址: <a href="http://www.nikhilk.net/Silverlight-Effects-Transitions.aspx" target="_blank">http://www.nikhilk.net/Silverlight-Effects-Transitions.aspx</a><br><br>Nikhil Kothari 在 blog 中介绍了一个叫做 Glitz 的动画框架，之所以需要这个框架，是因为 Silverlight 中已有的 Storyboard / Visual state manager 太原始，无法简单的提供一些常用的动画效果。<br><br>效果图（不知道这里直接引用图片是否有版权问题）：<br><img src="http://www.nikhilk.net/Content/Posts/SilverlightEffects/Weather.png"><br><br><img src="http://www.nikhilk.net/Content/Posts/SilverlightEffects/Effects.png"><br><br><br>该框架的实现方法和之前的 AutoComplete/ViewModel 等一样，仍然是采用了 Behavior 模式，通过 Attached Property 附加给目标元素。因为本质上动画也是一种可附加的行为。<br><br>这些动画行为分为两类： Effects（效果） 和 Transitions（过渡）。<br><br>其中 Effects 是指定给一个元素的，可以执行一些移动、淡入淡出等操作。<br>Effects 可以组合，利用 CompositeEffect.<br><br>而 Transitions 用于指定给一个 Panel 中的两个元素，使其出现切换效果。<br><br>不管是 Effects 或 Transitions，都支持设定动画播放的方向：向前，向后，或者向前播放后自动反转。<br><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);">&lt;</span><span style="color: rgb(128, 0, 0);">fxui:Button&nbsp;</span><span style="color: rgb(255, 0, 0);">Content</span><span style="color: rgb(0, 0, 255);">="Load"</span><span style="color: rgb(255, 0, 0);"><br>&nbsp;&nbsp;fxui:ButtonEvents.Click</span><span style="color: rgb(0, 0, 255);">="$model.LookupWeather(zipCodeTextBox.Text)"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fxglitz:Effects.ClickEffect</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);">fxglitz:SlideTransition&nbsp;</span><span style="color: rgb(255, 0, 0);">Mode</span><span style="color: rgb(0, 0, 255);">="Left"</span><span style="color: rgb(255, 0, 0);">&nbsp;TargetName</span><span style="color: rgb(0, 0, 255);">="layoutGrid"</span><span style="color: rgb(255, 0, 0);">&nbsp;Duration</span><span style="color: rgb(0, 0, 255);">="00:00:1.25"</span><span style="color: rgb(255, 0, 0);"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reversible</span><span style="color: rgb(0, 0, 255);">="False"</span><span style="color: rgb(255, 0, 0);">&nbsp;Easing</span><span style="color: rgb(0, 0, 255);">="ElasticInOut"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fxglitz:Effects.ClickEffect</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);">fxui:Button</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br></span></div><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);">&lt;</span><span style="color: rgb(128, 0, 0);">Border&nbsp;</span><span style="color: rgb(255, 0, 0);">Background</span><span style="color: rgb(0, 0, 255);">="#20000000"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fxglitz:Effects.HoverEffect</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);">fxglitz:ColorFillEffect&nbsp;</span><span style="color: rgb(255, 0, 0);">FillColor</span><span style="color: rgb(0, 0, 255);">="#80000000"</span><span style="color: rgb(255, 0, 0);">&nbsp;Duration</span><span style="color: rgb(0, 0, 255);">="00:00:0.5"</span><span style="color: rgb(255, 0, 0);">&nbsp;Easing</span><span style="color: rgb(0, 0, 255);">="QuadraticInOut"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fxglitz:Effects.HoverEffect</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;<img src="http://www.cnblogs.com/images/dot.gif"><br></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Border</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><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, 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, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid.RowDefinitions</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><img src="http://www.cnblogs.com/images/dot.gif"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid.RowDefinitions</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fxglitz:Effects.ClickEffect</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);">fxglitz:HighlightEffect&nbsp;</span><span style="color: rgb(255, 0, 0);">TargetName</span><span style="color: rgb(0, 0, 255);">="highlightImage"</span><span style="color: rgb(255, 0, 0);">&nbsp;HighlightColor</span><span style="color: rgb(0, 0, 255);">="Yellow"</span><span style="color: rgb(255, 0, 0);">&nbsp;Duration</span><span style="color: rgb(0, 0, 255);">="00:00:01"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fxglitz:Effects.ClickEffect</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Border&nbsp;</span><span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="highlightImage"</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);">Image&nbsp;</span><span style="color: rgb(255, 0, 0);">Source</span><span style="color: rgb(0, 0, 255);">="/Silverlight.png"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Border</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">TextBlock&nbsp;</span><span style="color: rgb(255, 0, 0);">Grid.Row</span><span style="color: rgb(0, 0, 255);">="1"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Highlight</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">TextBlock</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);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><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, 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, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid.RowDefinitions</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><img src="http://www.cnblogs.com/images/dot.gif"></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">Grid.RowDefinitions</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">fxglitz:Effects.ClickEffect</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);">fxglitz:FlipTransition&nbsp;</span><span style="color: rgb(255, 0, 0);">TargetName</span><span style="color: rgb(0, 0, 255);">="flipContainer"</span><span style="color: rgb(255, 0, 0);">&nbsp;Duration</span><span style="color: rgb(0, 0, 255);">="00:00:1"</span><span style="color: rgb(255, 0, 0);">&nbsp;Easing</span><span style="color: rgb(0, 0, 255);">="QuadraticInOut"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">fxglitz:Effects.ClickEffect</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">Grid&nbsp;</span><span style="color: rgb(255, 0, 0);">x:Name</span><span style="color: rgb(0, 0, 255);">="flipContainer"</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);">Image&nbsp;</span><span style="color: rgb(255, 0, 0);">Source</span><span style="color: rgb(0, 0, 255);">="/MS.net.png"</span><span style="color: rgb(255, 0, 0);">&nbsp;</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);">Image&nbsp;</span><span style="color: rgb(255, 0, 0);">Source</span><span style="color: rgb(0, 0, 255);">="/Silverlight.png"</span><span style="color: rgb(255, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br>&nbsp;&nbsp;</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, 0);"><br>&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">TextBlock&nbsp;</span><span style="color: rgb(255, 0, 0);">Style</span><span style="color: rgb(0, 0, 255);">="</span><span style="color: rgb(128, 128, 0);">{StaticResource&nbsp;staticText}</span><span style="color: rgb(0, 0, 255);">"</span><span style="color: rgb(255, 0, 0);">&nbsp;Grid.Row</span><span style="color: rgb(0, 0, 255);">="1"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Flip</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">TextBlock</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);">Grid</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br></span></div><br>（目前这个 Behavior 框架的一个小小缺憾是不能在 Expression Blend 中正常显示。我一般是切换到 Blend 时将相关代码注释掉，尽量先用 Blend 一次性布局好了再加 Behavior）<br><br>下载地址：<a href="http://www.nikhilk.net/Content/Posts/SilverlightEffects/SilverlightFX.zip" target="_blank">http://www.nikhilk.net/Content/Posts/SilverlightEffects/SilverlightFX.zip</a><br><br>几个效果的演示地址：<br><a href="http://www.nikhilk.net/Content/Posts/SilverlightEffects/WeatherSample.htm" target="_blank">http://www.nikhilk.net/Content/Posts/SilverlightEffects/WeatherSample.htm</a><br><a href="http://www.nikhilk.net/Content/Posts/SilverlightEffects/EffectsSample.htm" target="_blank">http://www.nikhilk.net/Content/Posts/SilverlightEffects/EffectsSample.htm</a><br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1257034.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41934/" target="_blank">[新闻]iPhone存在严重密码安全漏洞</a>]]></description></item><item><title>.net framework 3.5 beta 2 / vs 2008 beta 2 有问题！</title><link>http://www.cnblogs.com/RChen/archive/2008/07/30/1256851.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Wed, 30 Jul 2008 14:54:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/30/1256851.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1256851.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/30/1256851.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1256851.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1256851.html</trackback:ping><description><![CDATA[在我的 Silverlight + WCF 项目中，前些天一直好好的。<br>今天忽然不能添加/更新 Service Reference 了。<br>提示的信息是什么内存错误之类，经过事件日志分析也没有头绪。<br>最终卸载掉 .net framework 3.5 beta 2 / vs 2008 beta 2，<br>再修复一下 VS 2008, 问题解决！<br><br>错误信息：<br><br>.NET Runtime version 2.0.50727.3031 - 执行引擎错误(71D00DCE) (80131506)<br>.NET Runtime version 2.0.50727.3031 - 执行引擎错误(71F48C4E) (0)<br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1256851.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41931/" target="_blank">[新闻]GC2008：星际争霸2进程报告 微调进程延续</a>]]></description></item><item><title>几个微软产品组的团队网站地址</title><link>http://www.cnblogs.com/RChen/archive/2008/07/30/1256487.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Wed, 30 Jul 2008 07:09:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/30/1256487.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1256487.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/30/1256487.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1256487.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1256487.html</trackback:ping><description><![CDATA[<p class="MsoNormal" style="text-align: center;" align="center"><b><span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: SimSun;" lang="ZH-CN">微软产品组一直以来非常重视</span></b><b><span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black;">MVP</span></b><b><span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: SimSun;" lang="ZH-CN">对于微软产品的反馈信息，现邀请</span></b><b><span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black;">MVP</span></b><b><span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: SimSun;" lang="ZH-CN">对于相关网页进行预览并提出您对于相关网页的宝贵意见。同时，您也可以将以下网页网址放在您的</span></b><b><span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black;">Blog</span></b><b><span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: SimSun;" lang="ZH-CN">中，与其他</span></b><b><span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black;">IT</span></b><b><span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: SimSun;" lang="ZH-CN">同仁一同分享，让更多的人了解微软产品和技术的最新资讯。</span></b><b><span style="color: black;"><o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="color: black;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><b><span style="color: black; font-family: SimSun;" lang="ZH-CN">具体网页信息如下：</span></b><b><span style="color: black;"><o:p></o:p></span></b></p>
<p class="MsoListParagraph" style="margin-left: 0.25in; text-indent: -0.25in;"><b><span style="color: black;"><span style="">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></b><b><span style="color: black; font-family: SimSun;" lang="ZH-CN">微软中国研发集团服务器与开发工具事业部</span></b><b><span style="color: black;">: <a href="http://blogs.msdn.com/stbcblog"><span style="color: black;">http://blogs.msdn.com/stbcblog</span></a><o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="color: black; font-family: SimSun;" lang="ZH-CN">作为</span><span style="color: black;" lang="EN"><a href="http://www.microsoft.com/china/crd/default.mspx"><span style="color: black; font-family: SimSun;" lang="ZH-CN">微软中国研发集团</span></a></span><span style="color: black; font-family: SimSun;" lang="ZH-CN">的核心研发部门之一，服务器与开发工具事业部在上海和北京与总部及世界各地产品研发机构紧密配合，致力于为微软用户提供安全与访问、管理与服务、互连系统、数据平台、</span><span style="color: black;" lang="EN">Windows</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">服务器解决方案、商业在网服务和开发工具等核心产品与技术的研发和孵化。</span><span style="color: black;" lang="EN"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color: black; font-family: SimSun;" lang="ZH-CN">服务器与开发工具事业部还积极与本土合作伙伴展开战略合作，分享研发管理和产品开发的经验，将创新成果带给广大用户。此外，事业部还在中国吸纳和培养软件开发人才，致力于促进华东地区</span><span style="color: black;" lang="EN">IT</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">产业的繁荣和共赢。</span><span style="color: black;" lang="EN"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color: black; font-family: SimSun;" lang="ZH-CN">我们希望通过这个交流平台与学生、专业人士、用户进行近距离地沟通，分享我们中国</span><span style="color: black;" lang="EN">"</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">智</span><span style="color: black;" lang="EN">"</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">造的产品、技术，青年才俊们的成长点滴以及和团队文化。</span><span style="color: black;" lang="EN"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color: black; font-family: SimSun;" lang="ZH-CN">我们同时期待着您对我们的产品、技术、团队以及这个博客提供各种反馈。如果您对我们讨论的话题有任何建议，请给我们</span><span style="color: black;" lang="EN"><a href="http://blogs.msdn.com/stbcblog/contact.aspx"><span style="color: black; font-family: SimSun;" lang="ZH-CN">留言</span></a></span><span style="color: black; font-family: SimSun;" lang="ZH-CN">。</span><span style="color: black;" lang="EN"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color: black;" lang="EN"><o:p>&nbsp;</o:p></span></p>
<p class="MsoListParagraph" style="margin-left: 0.25in; text-indent: -0.25in;"><b><span style="color: black;"><span style="">2.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></b><b><span style="color: black;">SQL Server</span></b><b><span style="color: black; font-family: SimSun;" lang="ZH-CN">团队</span></b><b><span style="color: black;">: <a href="http://blogs.msdn.com/sqlcrd/" target="_blank"><span style="color: black;">http://blogs.msdn.com/sqlcrd/</span></a><o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="color: black;">SQL Server</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">中国研发团队将以创新为本，努力建设成为全球一流的研发中心，为全球用户提供针对企业级数据管理方面的产品研发及技术支持。同时也会更加深入地了解本地用户需求并做出快速响应，进而开发更加贴近和满足中国用户需求的解决方案。目前研发中心关注的领域主要包括：</span><span style="color: black;" lang="ZH-CN"> </span><span style="color: black; font-family: SimSun;" lang="ZH-CN">数据可编程性、商业智能以及开发工具的升级、管理和支持。</span><span style="color: black;"><o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left: 0.25in;"><span style="color: black;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoListParagraph" style="margin-left: 0.25in; text-indent: -0.25in;"><b><span style="color: black;"><span style="">3.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></b><b><span style="color: black;">CLR &amp; Silverlight</span></b><b><span style="color: black; font-family: SimSun;" lang="ZH-CN">团队</span></b><b><span style="color: black;">:<a href="http://blogs.msdn.com/silverlightshanghai/" target="_blank"><span style="color: black;">http://blogs.msdn.com/silverlightshanghai/</span></a> 
<o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="color: black;">CLR &amp; Silverlight</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">中国研发团队作为</span><span style="color: black;">.NET</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">开发平台组的一个研发团队，参与</span><span style="color: black;">CLR</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">（</span><span style="color: black;">Common Language Runtime</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">，公共语言运行时）以及</span><span style="color: black;">Silverlight</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">运行时底层</span><span style="color: black;">.NET</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">相关技术的研发。</span><span style="color: black;">CLR &amp; Silverlight</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">中国团队的博客旨在与广大</span><span style="color: black;">.NET</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">开发人员提供及时的</span><span style="color: black;">CLR</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">及</span><span style="color: black;">Silverlight</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">新闻，共享团队在研发过程中的点滴，交流与</span><span style="color: black;">CLR</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">及</span><span style="color: black;">Silverlight</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">相关的技术话题。</span><span style="color: black;"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="color: black;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoListParagraph" style="margin-left: 0.25in; text-indent: -0.25in;"><b><span style="color: black;"><span style="">4.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></b><b><span style="color: black;">WCF Tools</span></b><b><span style="color: black; font-family: SimSun;" lang="ZH-CN">团队</span></b><b><span style="color: black;">: <a href="http://blog.csdn.net/WCFToolsBloggers" target="_blank"><span style="color: black;">http://blog.csdn.net/WCFToolsBloggers</span></a> 
<o:p></o:p></span></b></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 11.9pt;"><span style="color: black; font-family: SimSun;" lang="ZH-CN">欢迎来到</span><span style="color: black;">WCF Tools</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">中国研发团队的小天地。我们团队</span><span style="color: black;">2006</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">年初在上海成立，全称是</span><span style="color: black;">“</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">互联架构和工具组</span><span style="color: black;">”(Connected Frameworks and Tools), </span><span style="color: black; font-family: SimSun;" lang="ZH-CN">隶属于微软中国研发集团服务器与开发工具事业部。我们的目标是充分利用本地人才和创新能力，进一步加强和推广微软的各种分布式的、面向服务的</span><span style="color: black;">(SOA)</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">架构和技术，包括</span><span style="color: black;">Windows Communications Foundation (WCF)</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">和</span><span style="color: black;">Workflow Foundation (WF)</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">。</span><span style="color: black;"><o:p></o:p></span></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 11.9pt;"><span style="color: black; font-family: SimSun;" lang="ZH-CN">迄今为止，我们已开发了</span><span style="color: black;">WCF</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">配置编辑器</span><span style="color: black;">(WCF Config Editor)</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">和</span><span style="color: black;">WCF</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">服务跟踪查看器</span><span style="color: black;">(Trace Viewer) ,</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">　两个包含在</span><span style="color: black;">Windows SDK </span><span style="color: black; font-family: SimSun;" lang="ZH-CN">和</span><span style="color: black;"> 
Visual Studio 2008</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">中的</span><span style="color: black;">WCF</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">管理工具。同时我们为</span><span style="color: black;">Visual Studio 2008</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">专门打造了一套</span><span style="color: black;">WCF </span><span style="color: black; font-family: SimSun;" lang="ZH-CN">开发工具，大大简化了</span><span style="color: black;">WCF</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">系统开发的流程。参加过</span><span style="color: black;">2007</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">年微软技术大会（</span><span style="color: black;">TechEd</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">）北京的朋友们大概还记得我们的展台和讲座。</span><span style="color: black;"><o:p></o:p></span></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 11.9pt;"><span style="color: black; font-family: SimSun;" lang="ZH-CN">我们已开始参与下一代</span><span style="color: black;">Workflow Foundation</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">组件的开发。我们的博客将涉及</span><span style="color: black;">WCF</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">工具，</span><span style="color: black;">WCF, WF</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">以及与</span><span style="color: black;">SOA</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">相关的一些信息和话题。我们希望以此建立与广大中国</span><span style="color: black;">IT</span><span style="color: black; font-family: SimSun;" lang="ZH-CN">人员交流的渠道。欢迎大家随时提问并提出宝贵建议。</span><span style="color: black;"><o:p></o:p></span></p><p class="MsoNormal" style="background: white none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 11.9pt;"><br></p><img src ="http://www.cnblogs.com/RChen/aggbug/1256487.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41931/" target="_blank">[新闻]GC2008：星际争霸2进程报告 微调进程延续</a>]]></description></item><item><title>Silverlight 2 beta 2 中目前不支持共享 WCF 的客户端类型</title><link>http://www.cnblogs.com/RChen/archive/2008/07/27/1252664.html</link><dc:creator>木野狐(Neil Chen)</dc:creator><author>木野狐(Neil Chen)</author><pubDate>Sun, 27 Jul 2008 10:12:00 GMT</pubDate><guid>http://www.cnblogs.com/RChen/archive/2008/07/27/1252664.html</guid><wfw:comment>http://www.cnblogs.com/RChen/comments/1252664.html</wfw:comment><comments>http://www.cnblogs.com/RChen/archive/2008/07/27/1252664.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnblogs.com/RChen/comments/commentRss/1252664.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/RChen/services/trackbacks/1252664.html</trackback:ping><description><![CDATA[在调用多个 WCF Service 的时候经常会遇到的一个问题是，某些同样的类型因为在不同的 Service 里用到，就被重复生成了好几个版本的代理类型，分别处在不同的名称空间下。<br><br>这样，如果一个操作需要同时调用几个 Service，就会面临冲突，假设 A 和 B 是因为不同的 WCF Service 生成的同一个类型的不同代理。那么只有通过代码把 A 的数据复制到 B. 这样显然很麻烦。<br><br>WCF 客户端类型共享可以通过创建一个专门的类库项目来实现，在该类库中用“添加服务引用”来生成客户端代理。<br>并且，让这个类库引用你需要共享的类型所在的 Assembly.<br><br>但因为 Silverlight 程序只能引用 Silverlight 的类库，它和 WCF 服务中调用到的类型处在不同的 .NET Framework.<br>这样就导致了“在代理的类库项目添加要共享的类型所在的 Assembly”这个步骤没法实现。因而无法共享客户端代理类型。<br><br>期待这个问题可以在 2.0 正式发布时得到解决吧。<br><br><img src ="http://www.cnblogs.com/RChen/aggbug/1252664.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41930/" target="_blank">[新闻]科学家在世界最大对撞机中观察到首批粒子</a>]]></description></item><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>7</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><font color="#ff0000">补充：</font><br>如果需要同时更新多个控件，则可以通过他们共同的祖先控件的 Dispatcher 来调用。<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/41929/" target="_blank">[新闻]阿里巴巴利润增1.36倍</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>2</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/41928/" target="_blank">[新闻]Google Gears覆盖四大浏览器 Safari版推出</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>2. Grid 布局中不能改变元素的叠放次序<br><br>&nbsp;&nbsp; 其实可以！！在元素中设置 Canvas.ZIndex 属性即可。这个确实很搞，很明显 ZIndex 这个属性设计的位置搞错了，应该放到 Grid 和 Canvas 共同的基类：Panel 中去。<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/41928/" target="_blank">[新闻]Google Gears覆盖四大浏览器 Safari版推出</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>1</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/41927/" target="_blank">[新闻]Internet Explorer 8 Beta 2 发布</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/41927/" target="_blank">[新闻]Internet Explorer 8 Beta 2 发布</a>]]></description></item></channel></rss>