<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet href='http://feed.feedsky.com/styles/feedsky1.xsl' type='text/xsl' ?><!--这是一个由Feedsy提供技术支持的Feed，为了提高读者阅读的体验，以及满足用户美化自己Feed的需要，我们设计了多种精美的Feed模板，提供给大家选择，所有最终呈现出来的样式，皆由用户自愿选择使用，未经许可，任何团体和个人，请不要擅自修改样式或者盗用，这是对于用户选择权的尊重。--><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://www.feedsky.com/namespace/feed" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link href="http://feed.feedsky.com/allan" type="application/rss+xml" rel="self"></atom:link><fs:self_link href="http://feed.feedsky.com/allan" type="application/rss+xml"></fs:self_link><lastBuildDate>Fri, 29 Aug 2008 12:14:25 GMT</lastBuildDate><title>Allan.Blog()</title><description>Let your soul be your pilot...</description><link>http://allan.flashempire.net/blog</link><language>en</language><pubDate>Fri, 29 Aug 2008 12:14:25 GMT</pubDate><item><title>欢迎参与字体的小调查</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285354/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=557</wfw:commentRss><description>做个小调查,希望了解更多用户对字体大小与舒适度之间的选择,欢迎参加
http://beta.nxmix.com/webfontsurvey</description><category>生活杂技</category><pubDate>Fri, 29 Aug 2008 20:14:25 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=557#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=557</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=557</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285354/1221089</fs:itemid></item><item><title>JavaScript与Silverlight的通信</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285355/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=556</wfw:commentRss><description>一看代码就明白了,不用多说,贴此备忘,原贴出处

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
namespace SilverlightApplication
&amp;#123;
    public partial class Page : UserControl
    &amp;#123;
        public Page&amp;#40;&amp;#41;
        &amp;#123;
            InitializeComponent&amp;#40;&amp;#41;;
&amp;#160;
            [...]</description><category>中文Silverlight资源</category><category>Silverlight</category><pubDate>Wed, 09 Jul 2008 15:01:07 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=556#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=556</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=556</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285355/1221089</fs:itemid></item><item><title>El Orfanato</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285356/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=555</wfw:commentRss><description>El Orfanato《孤儿院》很不错的一部西班牙电影,很牛的一部片子!该片的制片人Guillermo del Toro曾是二年前获奖无数的《潘神的迷宫》的导演.影片很不错,可以当一片悬疑片去解读,也可以当一部温情电影,如果愿花功夫,可以当一部心理片来看,去更深层的解读一下片中的空间与幻想间的关系</description><category>Movie &amp;#038; Music</category><pubDate>Sat, 28 Jun 2008 22:27:07 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=555#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=555</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=555</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285356/1221089</fs:itemid></item><item><title>DispatcherTimer vs Storyboard</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285357/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=551</wfw:commentRss><description>在Silverlight做逐帧事件可以用DispatcherTimer计时器,或使用一个空的Storyboard，在每次Completed事件中写你的执行代码然后再启动Storyboard，但是哪一种更好呢？这里有一个解释来自Adam Kinney:
The DispatcherTimer is a lower resolution timer than the timer behind the Storyboard class, which causes loss in fidelity. Additionally, the Storyboard execution is more stable across the different supported OSs and Browsers. I&amp;#8217;ll put together a sample to show the comparision.
不管怎样使用空的Storyboard来做逐帧是一个很好的解决方案,为此我设计了一个用于替代DispatcherTimer的StoryboardTimer类,可以在程序中和使用DispatcherTimer一样使用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    public class StoryboardTimer
    &amp;#123;
   [...]</description><category>Silverlight</category><pubDate>Thu, 26 Jun 2008 16:51:48 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=551#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=551</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=551</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285357/1221089</fs:itemid></item><item><title>[翻译]Part&amp;States Model With VisualStateManager(4/4)</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285358/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=550</wfw:commentRss><description>[原文地址]
这是有关&amp;#8221;部件与状态&amp;#8221;模式系列的最后一篇!
今天,我们讨论一些关于如何使用&amp;#8221;部件与状态&amp;#8221;模式的使用建议.我们还会看看有关VisualStageManager在未来的Silverlight及WPF中的情况.
系列链接(第一篇,第二篇,第三篇,第四篇)
&amp;#8220;部件与状态&amp;#8221;模式使用推荐
1.在UserControls用户控件和Custom Control自定义控件中使用&amp;#8221;部件与状态&amp;#8221;模式
就像我们在第一篇中提到的,&amp;#8221;部件与状态&amp;#8221;模式只是一个模式.在实际运行中并不是强制的,你可以在创建控件时不采用这种方式.
但是,我们觉得这是一个很好的模式.而且Blend针对自定义控件的的可视化编辑方式只支持这种模式.
虽然我们这一系列一直关注在自定义控件Custom Controls中的VSM,但是你同样可以在用户控件User Control中使用他.
2.自行命名VSM xmlns
因为一个已知的Silverlight 2 Beta 2 Bug,你必须在头部申明VisualStateManager的xmlns.

1
xmlns:vsm=“clr-namespace:System.Windows;assembly=System.Windows”

3.命名约定
为了控件的一致性,我们推荐使用如下的一些命名约定.

4.CommonStates 和 FocusStates 比较特殊
许多控件都使用了这二个状态组

如果你的控件也有这些状态的特征,为了一致性,我们推荐使用相同的组名和名称
5.能够适应模板中没有Parts &amp;#038; States的情况
有很多原因能说明为什么控件模板中没有给一些部件和状况:设计师可能没有创建等原因.
需要有一些良好的编写习惯去防止由于部件遗失造成的程序崩溃.
注意:VisualStateManager.GoToState()方法已经有这种预防措施,当VisualState没有找到时,会返回false.
6.考虑支持一个&amp;#8221;fallback&amp;#8221;状态(当状态不存在时,用另一状态替代)
在复杂的控件中,可以提供一个fallback控制当某些状态不存在时提供一种替代方案

1
2
3
4
if &amp;#40;VisualStateManager.GoToState&amp;#40;this, “FocusContent”, useTransitions&amp;#41; == false&amp;#41;
&amp;#123;
VisualStateManager.GoToState&amp;#40;this, “Focus&amp;#34;, useTransitions);
}</description><category>中文Silverlight资源</category><category>Silverlight</category><pubDate>Thu, 26 Jun 2008 12:05:46 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=550#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=550</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=550</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285358/1221089</fs:itemid></item><item><title>真正的Loaded事件</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285359/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=549</wfw:commentRss><description>做了一些Silverlight开发应该知道,在Loaded事件之后的那个handler之中,画面并没有实际的被layout出来,在Loaded的时候是获得不了ActualWidth或其它相关值的,而只有在Layoutupdated事件中才能获得,但Layoutupdated事件是经常会运行,容易消耗资源,因此有必要找到一个方法,在画面正确渲染出来后,也就是被layouted时,来进行一些操作,之前在WPF中采用过这样一个方法,在这几天也在想办法在Silverlight找寻类似的方法,结论代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//构造中加Loaded事件
Loaded+=new RoutedEventHandler&amp;#40;Page_Loaded&amp;#41;;
&amp;#160;
//Loaded Event handler
void Page_Loaded&amp;#40;object sender, RoutedEventArgs e&amp;#41;
        &amp;#123;
            Debug.WriteLine&amp;#40;&amp;#34;Loaded Event:&amp;#34;+this.ActualWidth&amp;#41;;
&amp;#160;
            Thread thread = new Thread&amp;#40;new ThreadStart&amp;#40;&amp;#40;&amp;#41; =&amp;#62;
         [...]</description><category>中文Silverlight资源</category><category>Silverlight</category><pubDate>Wed, 25 Jun 2008 14:47:07 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=549#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=549</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=549</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285359/1221089</fs:itemid></item><item><title>简化Animation语法</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285360/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=548</wfw:commentRss><description>如果你不想在new一个DoubleAnimation()后，做大量的From,To,Duration的操作的话，可以试试C#所支持的简写对象的方式,而且在VS的智能感知中就能原生的支持

简写前

1
2
3
4
DoubleAnimation opacityAnimation = new DoubleAnimation&amp;#40;&amp;#41;
opacityAnimation.From = 0;
opacityAnimation.To = 1;
opacityAnimation.Duration = duration;

简写后

1
DoubleAnimation opacityAnimation = new DoubleAnimation&amp;#40;&amp;#41; &amp;#123; From = 0, To = 1, Duration = duration&amp;#125;;</description><category>中文Silverlight资源</category><category>Silverlight</category><pubDate>Wed, 25 Jun 2008 14:02:41 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=548#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=548</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=548</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285360/1221089</fs:itemid></item><item><title>[翻译]Part&amp;States Model With VisualStateManager(3/4)</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285361/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=547</wfw:commentRss><description>[原文地址]
这是系列教程的第三篇.
上一次,你学会了如何对现有的控件使用VisualStateManager来改变皮肤外观.在这一篇中,你会看到如何创建基于&amp;#8221;部件&amp;#8221;与&amp;#8221;状态&amp;#8221;的自定义控件.同时我们还会探索创建一些更精密复杂的视觉过渡效果.
视觉状态管理器VisualStageManger
在上一篇中我们曾简述过,但现在我们正式的介绍VisualStageManager视觉状态管理器

VisualStateManager是一个类,用来管理控件的视觉状态.&amp;#8221;Visual&amp;#8221;是关键字(用来管理视觉,非逻辑)-控件的逻辑仍然只负责逻辑状态.
VSM暴露PME的二个片段:

一个VisualStageGroups attached property(附加属性)

这个属性放在控件模板的RootVisual并包含所有与外观有关的视觉状态与过渡效果


一个静态GoToStage()方法

这个方法的产生原因是因为VisualStageManager需要来控制控件的视觉由一个视觉状态过渡到其它状态



上一次,我们专注于XAML中的VisualStageGroups属性.今天,我们深入到控件的代码中的GoToStage()方法.
WeatherControl
我们今天会来看一个简单的自定义控件 WeatherControl. 控件的部分代码可以在下面看到.(注意:为了可读性,我折叠了一些代码片段,你可以从这里找到完整的代码.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    public class WeatherControl : Control
    &amp;#123;
&amp;#160;
&amp;#160;
        public WeatherControl&amp;#40;&amp;#41;
        &amp;#123;
            DefaultStyleKey = typeof&amp;#40;WeatherControl&amp;#41;;
        [...]</description><category>中文Silverlight资源</category><category>Silverlight</category><pubDate>Tue, 24 Jun 2008 19:06:54 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=547#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=547</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=547</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285361/1221089</fs:itemid></item><item><title>Silverlight中的Mask动画</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285362/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=545</wfw:commentRss><description>之前也有很多人问我,我当时也不敢肯定,觉得应该是没有,但结果是, Silverlight中的确支持对Clip的值进行动画,如图:

方法是这样,给对象建立Clip后,在故事板中,可以右键单击这个对象,Release Clip,把Clip对象分离出来, 然后在时间线上给Clip做动画,再在时间线上把Clip对象与原对象组合为带Clip的对象,Over!
需要补充的是,针对Clip Path的动画只能是针对Clip中的各节点进行控制，如果你对一个Path执行RendTranform中的各种变化，那么再把Clip组合回对象的话，就无法记录动画，如果想做位移，就只能调整各节点，或选择所有节点，进行一个运动．．使Blend为这个Clip形成一些Segment Path方面的动画</description><category>中文Silverlight资源</category><category>Silverlight</category><pubDate>Fri, 20 Jun 2008 11:14:44 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=545#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=545</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=545</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285362/1221089</fs:itemid></item><item><title>[翻译]Part&amp;States Model With VisualStateManager(2/4)</title><link>http://item.feedsky.com/~feedsky/allan/~1219418/109285363/1221089/1/item.html</link><wfw:commentRss>http://allan.flashempire.net/blog/?feed=rss2&amp;p=544</wfw:commentRss><description>原文地址
这是四篇关于介绍Silverlight 2 控件的&amp;#8221;部件&amp;#8221;与&amp;#8221;状态&amp;#8221;系列中的第二篇.
今天,我们将概念进行实践,实现上次所说的CheckBox的换肤(如果你还没读过上一篇,请先读第一篇).
注意:为了方便阅读我尽可能减短XAML标签.你可以从这里下载完整的代码
CheckBox的控件模板(ControlTemplate)
控件模板定义自定义控件的视觉呈现.CheckBox的控件模板代码我们下面有贴出来.
视觉效果:

XAML:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
&amp;#60;ControlTemplate TargetType=&amp;#34;CheckBox&amp;#34;&amp;#62;
  &amp;#60;StackPanel x:Name=&amp;#34;Root&amp;#34; …&amp;#62;
    &amp;#60;!– OuterBorder –&amp;#62;
    &amp;#60;Border Width=&amp;#34;20&amp;#34; Height=&amp;#34;20&amp;#34; … &amp;#62;
&amp;#160;
    &amp;#60;!– InnerBorder –&amp;#62;
    &amp;#60;Border x:Name=&amp;#34;InnerBorder&amp;#34;  … &amp;#62;
    &amp;#60;Grid&amp;#62;
&amp;#160;
      &amp;#60;!– Higlight–&amp;#62;
      &amp;#60;Border x:Name=&amp;#34;HighlightBorder&amp;#34; … [...]</description><category>生活杂技</category><category>中文Silverlight资源</category><pubDate>Thu, 19 Jun 2008 22:07:35 +0800</pubDate><author>Allan</author><comments>http://allan.flashempire.net/blog/?p=544#comments</comments><guid isPermaLink="false">http://allan.flashempire.net/blog/?p=544</guid><dc:creator>Allan</dc:creator><fs:srclink>http://allan.flashempire.net/blog/?p=544</fs:srclink><fs:srcfeed>http://allan.flashempire.net/blog/?feed=rss2</fs:srcfeed><fs:itemid>feedsky/allan/~1219418/109285363/1221089</fs:itemid></item></channel></rss>
