<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>DWS - Deep Water Software</title>
	
	<link>http://www.miroslavov.com</link>
	<description>by Miro Miroslavov</description>
	<lastBuildDate>Mon, 24 Oct 2011 14:17:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DeepWaterSoftware" /><feedburner:info uri="deepwatersoftware" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Stronger Silverlight community in Bulgaria</title>
		<link>http://feedproxy.google.com/~r/DeepWaterSoftware/~3/1kKQxsn16UY/</link>
		<comments>http://www.miroslavov.com/?p=212#comments</comments>
		<pubDate>Mon, 12 Apr 2010 15:37:45 +0000</pubDate>
		<dc:creator>Miroslav Miroslavov</dc:creator>
				<category><![CDATA[Bulgarian Community]]></category>
		<category><![CDATA[Bulgaria]]></category>
		<category><![CDATA[Community]]></category>

		<guid isPermaLink="false">http://www.miroslavov.com/?p=212</guid>
		<description><![CDATA[Silverlight&#8217;s community in Bulgaria is getting stronger every day, due to a couple of reasons: The course we&#8217;re having at The University of Sofia. Currently we have more than 100 students eager to know and start using Silverlight. Till now we had 5 very good lectures and nice demos in Bulgarian language. The very strong &#8230; </p><p><a class="more-link block-button" href="http://www.miroslavov.com/?p=212">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Silverlight&#8217;s community in Bulgaria is getting stronger every day, due to a couple of reasons:</p>
<ul>
<li> <a href="http://fmi.silverlight.bg/">The course </a>we&#8217;re having at The University of Sofia. Currently we have more than 100 students eager to know and start using Silverlight. Till now we had 5 very good lectures and nice demos in Bulgarian language.</li>
<li>The very strong and permanent <a href="http://silverlight.bg/">Sofia&#8217;s Silverlight group</a>. We meet every month to share and learn &#8220;What&#8217;s new&#8221; and &#8220;How to&#8221;  with Silverlight.</li>
</ul>
<p>You can also meet the Bulgaria&#8217;s Silverlight MVP &#8211; Emil Stoychev at <a href="http://microsoftfeed.com/2010/meet-emil-stoychev-silverlight-mvp-from-bulgaria/#more-4237">MicrosoftFeed</a>.</p>
<img src="http://feeds.feedburner.com/~r/DeepWaterSoftware/~4/1kKQxsn16UY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.miroslavov.com/?feed=rss2&amp;p=212</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.miroslavov.com/?p=212</feedburner:origLink></item>
		<item>
		<title>The Silverlight Performance tips list</title>
		<link>http://feedproxy.google.com/~r/DeepWaterSoftware/~3/f73ByqFbifE/</link>
		<comments>http://www.miroslavov.com/?p=159#comments</comments>
		<pubDate>Wed, 07 Apr 2010 22:09:42 +0000</pubDate>
		<dc:creator>Miroslav Miroslavov</dc:creator>
				<category><![CDATA[Silverlight in action]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.miroslavov.com/?p=159</guid>
		<description><![CDATA[This list with performance tips is collected from many sources, including my personal experience. It is supposed to evolve and grow in the future. Basic performance tips, regarding your code Minimize your XAML &#8211; the smaller the better. Do not allow Blend or VS to blow it up. Always think about &#8220;The Visual Tree&#8221;. Keep &#8230; </p><p><a class="more-link block-button" href="http://www.miroslavov.com/?p=159">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>This list with performance tips is collected from many sources, including my personal experience. It is supposed to evolve and grow in the future.</p>
<h3>Basic performance tips, regarding your code</h3>
<ul>
<li>Minimize your XAML &#8211; the smaller the better. Do not allow Blend or VS to blow it up.</li>
<li>Always think about &#8220;The Visual Tree&#8221;. Keep it small. Understand all controls with their visual trees. Use the simplest controls that will work in your case.</li>
<li>Always collapse not needed UIElements or remove them from the Visual Tree.</li>
<li>
<div>Opacity = 0 is different from Visibility = Collapsed.</div>
</li>
<li>Use Image.Stretch = &#8220;Fill&#8221; to prevent any layout updates due to  stretching, whenever is possible.</li>
<li>Do NOT use Path with explicit Height/Width values and do NOT allow parent controls to stretch it. Paths are supposed to be as big as the Data property says (Unless you don&#8217;t need it).</li>
</ul>
<h3>Silverlight Plug-in options</h3>
<ul>
<li>Avoid Using Windowless Mode</li>
<li>Use Transparent Background only when needed</li>
</ul>
<h3>Animations</h3>
<ul>
<li>Always be aware of the frame-rate.
<ul>
<li>Think about the frame-rate on per Animation bases. More about this <a href="http://www.miroslavov.com/index.php/2010/03/silverlight-animations-and-the-missing-timeline-desiredframerate/">here</a>.</li>
</ul>
</li>
<li>Big moving elements are always CPU expensive (Due to big redrawn regions).</li>
<li>Understand each animation how expensive is.</li>
<li>Understand CompositionTarget.Rendering event and use it if possible.</li>
<li>Storyboards and animations over big regions are very expensive. Try to minimize them.</li>
<li>Do not allow layout pass while animation is running (unless this is what you need). This means not to animate properties that are related to the Layout system like Height, Width, Visibility, Alignments, Margins&#8230;</li>
<li>Text Animations &#8211; By default, Silverlight optimizes text for readability. That&#8217;s why animating text is expensive. Unless we do one of the following.
<ul>
<li>Set TextRenderingMode = RenderForAnimation</li>
<li>If the text is static, we can replace it with Image of the text and animate the Image control.</li>
</ul>
</li>
</ul>
<h3>Monitor the performance during development</h3>
<ul>
<li>MaxFrameRate = 10.000</li>
<li>EnableFrameRateCounter = true</li>
<li>EnableRedrawRegions = true</li>
<li>Use <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx">Process Explorer </a>to monitor the CPU usage</li>
</ul>
<h3>Advanced tips</h3>
<h4>UI Caching</h4>
<ul>
<li>
<h4>WriteableBitmap &#8211; more on this <a href="http://www.miroslavov.com/index.php/2010/04/performance-optimizations-using-writeablebitmap/">here</a>.</h4>
</li>
<li>
<h4>GPU cache &#8211; more on this <a href="http://blogs.msdn.com/silverlight_sdk/archive/2009/07/09/silverlight-cached-composition.aspx">here</a>.</h4>
</li>
</ul>
<p>Can be very useful when cached elements are being translated, scaled, rotated or blended using opacity. Also it will work better if the cached elements are Leaf nodes in the visual tree.</p>
<ul>
<li> Limitations: You can&#8217;t cache elements that have been:
<ul>
<li> Projected using Plane/MatrixProjections</li>
<li> Applied effect, including Pixel Shader.</li>
<li> Applied opacity mask.</li>
<li> Applied non-rectangular clipping.</li>
</ul>
</li>
</ul>
<p>In order to make this list more helpful &#8211; all comments are more than welcome.</p>
<img src="http://feeds.feedburner.com/~r/DeepWaterSoftware/~4/f73ByqFbifE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.miroslavov.com/?feed=rss2&amp;p=159</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.miroslavov.com/?p=159</feedburner:origLink></item>
		<item>
		<title>Performance optimizations using WriteableBitmap</title>
		<link>http://feedproxy.google.com/~r/DeepWaterSoftware/~3/rv531Vx59eA/</link>
		<comments>http://www.miroslavov.com/?p=147#comments</comments>
		<pubDate>Sun, 04 Apr 2010 21:55:12 +0000</pubDate>
		<dc:creator>Miroslav Miroslavov</dc:creator>
				<category><![CDATA[Silverlight in action]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WriteableBitmap]]></category>

		<guid isPermaLink="false">http://www.miroslavov.com/?p=147</guid>
		<description><![CDATA[See it in Action. Just drag the mouse before and after clicking 'cache them'. Also can check the CPU usage at the moments of dragging. The old time Bitmap Caching is very useful performance optimization technique. And as we know we have good support for it in Silverlight. To cache an UIElements in the GPU &#8230; </p><p><a class="more-link block-button" href="http://www.miroslavov.com/?p=147">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<pre>See it in Action. Just drag the mouse before and after clicking 'cache them'.
Also can check the CPU usage at the moments of dragging. </pre>
<p><div id="silverlightControlHost"><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="480" height="300"><param name="source" value="http://www.miroslavov.com/Silverlight/WriteableBitmapTest.xap"/><param name="background" value="white" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="autoupgrade" value="true" /><param name="enableHtmlAccess" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156" style="text-decoration: none;"><img src="http://storage.timheuer.com/sl4wp-ph.png" alt="Install Microsoft Silverlight" style="border-style: none; width:400px; height:200px"/></a></object><iframe style="visibility:hidden;height:0;width:0;border:0px" id="_sl_historyFrame"></iframe></div><br /></p>
<p>The old time <em>Bitmap Caching </em>is very useful performance optimization technique. And as we know we have good support for it in Silverlight. To cache an UIElements in the GPU memory is as easy as setting one property (CacheMode =&#8221;BitmapCache&#8221;) and enable it on the plug-in level (EnableGPUAccelaration = true). But this has a lot of limitations in Silverlight 3 (and little more features in Silverlight 4 &#8211; we&#8217;ll be able to cache objects that have been Projected).</p>
<p>But the limitations with GPU caching are driving us to one other option &#8211; to implement <em>Bitmap Caching </em>at our own. So we&#8217;ll &#8220;paint&#8221; our UIElements to Bitmap with WriteableBitmap API that Silverlight provide. This could be very helpful in a case that we have a lot of UIElements in the Visual Tree that are somehow static at the moment, and we&#8217;re suppose to start animation on some other objects.</p>
<h4>The Algorithm</h4>
<ol>
<li> Cache the static elements with WriteableBitmap</li>
<li>Remove them from the Visual Tree</li>
<li>Insert on their place the newly created Image</li>
<li>Animate something or do some expensive UI work over very lighter Visual Tree</li>
<li>Enjoy the much better User Experience</li>
</ol>
<p>For the example we&#8217;ll generate 300 random Borders and will Project them.</p>
<h4>And the code itself</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">WriteableBitmap bitmapCache <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WriteableBitmap<span style="color: #008000;">&#40;</span>ObjectsCanvas, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
InnerGrid<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>ObjectsCanvas<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
CacheImage<span style="color: #008000;">.</span><span style="color: #0000FF;">Source</span> <span style="color: #008000;">=</span> bitmapCache<span style="color: #008000;">;</span></pre></td></tr></table></div>

<h4>XAML</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;InnerGrid&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">WriteableBitmapTest:DraggingBehavior.IsDraggable</span>=<span style="color: #ff0000;">&quot;True&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Canvas</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;ObjectsCanvas&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;Transparent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;CacheImage&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span> <span style="color: #000066;">Content</span>=<span style="color: #ff0000;">&quot;Cache them!&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">Click</span>=<span style="color: #ff0000;">&quot;Button_Click&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Top&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>I&#8217;ve used this technique in a couple of projects with very good success. In <a href="http://miroslavov.com/graph/default.html"><em>Graph My Code</em></a> when you search for item or click it, the whole thing is cached and you&#8217;ll experience smoother animations.</p>
<h4><a href="http://www.miroslavov.com/wordpress/wp-content/uploads/2010/04/WriteableBitmapTest1.zip">Download code here!</a></h4>
<img src="http://feeds.feedburner.com/~r/DeepWaterSoftware/~4/rv531Vx59eA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.miroslavov.com/?feed=rss2&amp;p=147</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.miroslavov.com/?p=147</feedburner:origLink></item>
		<item>
		<title>Transitioning Frame – Animation between pages</title>
		<link>http://feedproxy.google.com/~r/DeepWaterSoftware/~3/koapaYPVo7Q/</link>
		<comments>http://www.miroslavov.com/?p=133#comments</comments>
		<pubDate>Fri, 02 Apr 2010 21:06:25 +0000</pubDate>
		<dc:creator>Miroslav Miroslavov</dc:creator>
				<category><![CDATA[Silverlight in action]]></category>
		<category><![CDATA[Animations]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Pages]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.miroslavov.com/?p=133</guid>
		<description><![CDATA[This time I&#8217;ll talk about &#8220;How to enable animations between pages using the Navigation Framework&#8220;. So whenever we navigate to page using HyperlinkButton,  Browser history, Back / Forward browser buttons  or just navigate to a deep-link, we&#8217;ll be able to run animation between the content of the pages. This technique is very useful for both &#8230; </p><p><a class="more-link block-button" href="http://www.miroslavov.com/?p=133">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>This time I&#8217;ll talk about &#8220;<em>How to enable animations between pages using the Navigation Framework</em>&#8220;. So whenever we navigate to page using HyperlinkButton,  Browser history, Back / Forward browser buttons  or just navigate to a deep-link, we&#8217;ll be able to run animation between the content of the pages. This technique is very useful for both &#8211; Line Of Business Applications and Rich Internet Applications.</p>
<pre>Test it yourself.
</pre>
<p><div id="silverlightControlHost"><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="480" height="300"><param name="source" value="http://www.miroslavov.com/Silverlight/TransitionFrame.xap"/><param name="background" value="white" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="autoupgrade" value="true" /><param name="enableHtmlAccess" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156" style="text-decoration: none;"><img src="http://storage.timheuer.com/sl4wp-ph.png" alt="Install Microsoft Silverlight" style="border-style: none; width:400px; height:200px"/></a></object><iframe style="visibility:hidden;height:0;width:0;border:0px" id="_sl_historyFrame"></iframe></div><br /></p>
<p>I&#8217;ll inherit from the <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.frame%28VS.95%29.aspx">Frame</a> class, and lets name this class <em>TransitionFrame</em>. The Frame class is ContentControl with enabled some Navigation features. And the idea is pretty simple and well-known from the Toolkit&#8217;s TransitioningContentControl. We&#8217;ll have two ContentPresenters for both the current page and previous one, so this will allow us to run animation between the pages.</p>
<h4>TransitionFrame</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> TransitionFrame <span style="color: #008000;">:</span> Frame
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> ContentPresenter CurrentContentPresentationSite<span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> ContentPresenter PreviousContentPresentationSite<span style="color: #008000;">;&lt;/</span>code<span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> TransitionFrame<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
DefaultStyleKey <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span> <span style="color: #008000;">&#40;</span>TransitionFrame<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnApplyTemplate<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnApplyTemplate</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
PreviousContentPresentationSite <span style="color: #008000;">=</span> GetTemplateChild<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PreviousContentPresentationSite&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> ContentPresenter<span style="color: #008000;">;</span>
CurrentContentPresentationSite <span style="color: #008000;">=</span> GetTemplateChild<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;CurrentContentPresentationSite&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> ContentPresenter<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CurrentContentPresentationSite <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
CurrentContentPresentationSite<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span> <span style="color: #008000;">=</span> Content<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnContentChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> oldContent, <span style="color: #6666cc; font-weight: bold;">object</span> newContent<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnContentChanged</span><span style="color: #008000;">&#40;</span>oldContent, newContent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>CurrentContentPresentationSite <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> <span style="color: #008000;">&#40;</span>PreviousContentPresentationSite <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
CurrentContentPresentationSite<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span> <span style="color: #008000;">=</span> newContent<span style="color: #008000;">;</span>
PreviousContentPresentationSite<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span> <span style="color: #008000;">=</span> oldContent<span style="color: #008000;">;</span>
&nbsp;
VisualStateManager<span style="color: #008000;">.</span><span style="color: #0000FF;">GoToState</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, <span style="color: #666666;">&quot;Normal&quot;</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
VisualStateManager<span style="color: #008000;">.</span><span style="color: #0000FF;">GoToState</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, <span style="color: #666666;">&quot;Transition&quot;</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>I&#8217;ll use VisualStateManager for dealing with the animations. And lets define two states:</p>
<ul>
<li><strong><em>Transition</em> </strong>state &#8211; run the animation between pages. (change this to make custom animations)</li>
<li><strong><em>Normal</em></strong> state &#8211; enables the control to go back to Transition state, when needed.</li>
</ul>
<h4>ControlTemplate</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;{TemplateBinding HorizontalContentAlignment}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;{TemplateBinding VerticalContentAlignment}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;{TemplateBinding Background}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">BorderBrush</span>=<span style="color: #ff0000;">&quot;{TemplateBinding BorderBrush}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;{TemplateBinding BorderThickness}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VisualStateManager.VisualStateGroups<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VisualStateGroup</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PresentationStates&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>                                
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VisualState</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;Normal&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VisualState</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;Transition&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Storyboard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ObjectAnimationUsingKeyFrames</span> <span style="color: #000066;">BeginTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetName</span>=<span style="color: #ff0000;">&quot;PreviousContentPresentationSite&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetProperty</span>=<span style="color: #ff0000;">&quot;(UIElement.Visibility)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DiscreteObjectKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DiscreteObjectKeyFrame.Value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Visibility<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Visible<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Visibility<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DiscreteObjectKeyFrame.Value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DiscreteObjectKeyFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DiscreteObjectKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:01.300&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DiscreteObjectKeyFrame.Value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Visibility<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Collapsed<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Visibility<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DiscreteObjectKeyFrame.Value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DiscreteObjectKeyFrame<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ObjectAnimationUsingKeyFrames<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DoubleAnimationUsingKeyFrames</span> <span style="color: #000066;">BeginTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetName</span>=<span style="color: #ff0000;">&quot;CurrentContentPresentationSite&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetProperty</span>=<span style="color: #ff0000;">&quot;(UIElement.Opacity)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SplineDoubleKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span></span>
<span style="color: #009900;">                                              <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SplineDoubleKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:00.300&quot;</span></span>
<span style="color: #009900;">                                              <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DoubleAnimationUsingKeyFrames<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DoubleAnimationUsingKeyFrames</span> <span style="color: #000066;">BeginTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetName</span>=<span style="color: #ff0000;">&quot;CurrentContentPresentationSite&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetProperty</span>=<span style="color: #ff0000;">&quot;(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SplineDoubleKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span></span>
<span style="color: #009900;">                                              <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SplineDoubleKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:00.300&quot;</span></span>
<span style="color: #009900;">                                              <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DoubleAnimationUsingKeyFrames<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DoubleAnimationUsingKeyFrames</span> <span style="color: #000066;">BeginTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetName</span>=<span style="color: #ff0000;">&quot;PreviousContentPresentationSite&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetProperty</span>=<span style="color: #ff0000;">&quot;(UIElement.Opacity)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SplineDoubleKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span></span>
<span style="color: #009900;">                                              <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SplineDoubleKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:00.300&quot;</span></span>
<span style="color: #009900;">                                              <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DoubleAnimationUsingKeyFrames<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DoubleAnimationUsingKeyFrames</span> <span style="color: #000066;">BeginTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetName</span>=<span style="color: #ff0000;">&quot;PreviousContentPresentationSite&quot;</span></span>
<span style="color: #009900;">                                                   <span style="color: #000066;">Storyboard.TargetProperty</span>=<span style="color: #ff0000;">&quot;(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SplineDoubleKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:00&quot;</span></span>
<span style="color: #009900;">                                              <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SplineDoubleKeyFrame</span> <span style="color: #000066;">KeyTime</span>=<span style="color: #ff0000;">&quot;00:00:00.300&quot;</span></span>
<span style="color: #009900;">                                              <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;-100&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DoubleAnimationUsingKeyFrames<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>   
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Storyboard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/VisualState<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>                                
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/VisualStateGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/VisualStateManager.VisualStateGroups<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ContentPresenter</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PreviousContentPresentationSite&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">Content</span>=<span style="color: #ff0000;">&quot;{x:Null}&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">ContentTemplate</span>=<span style="color: #ff0000;">&quot;{TemplateBinding ContentTemplate}&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;{TemplateBinding HorizontalContentAlignment}&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;{TemplateBinding VerticalContentAlignment}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ContentPresenter.RenderTransform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TransformGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ScaleTransform</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SkewTransform</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RotateTransform</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TranslateTransform</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TransformGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ContentPresenter.RenderTransform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ContentPresenter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ContentPresenter</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;CurrentContentPresentationSite&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">Content</span>=<span style="color: #ff0000;">&quot;{x:Null}&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">ContentTemplate</span>=<span style="color: #ff0000;">&quot;{TemplateBinding ContentTemplate}&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;{TemplateBinding HorizontalContentAlignment}&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;{TemplateBinding VerticalContentAlignment}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ContentPresenter.RenderTransform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TransformGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ScaleTransform</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SkewTransform</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RotateTransform</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TranslateTransform</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TransformGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ContentPresenter.RenderTransform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ContentPresenter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<h3><a href="http://www.miroslavov.com/wordpress/wp-content/uploads/2010/04/TransitionFrame.zip">Download Source Code</a></h3>
<img src="http://feeds.feedburner.com/~r/DeepWaterSoftware/~4/koapaYPVo7Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.miroslavov.com/?feed=rss2&amp;p=133</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.miroslavov.com/?p=133</feedburner:origLink></item>
		<item>
		<title>MS Days 2010 @ Sofia, Bulgaria</title>
		<link>http://feedproxy.google.com/~r/DeepWaterSoftware/~3/Kq_PiGGFbEA/</link>
		<comments>http://www.miroslavov.com/?p=104#comments</comments>
		<pubDate>Wed, 31 Mar 2010 22:07:21 +0000</pubDate>
		<dc:creator>Miroslav Miroslavov</dc:creator>
				<category><![CDATA[CompletIT]]></category>
		<category><![CDATA[Speaks]]></category>
		<category><![CDATA[MS Days]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.miroslavov.com/?p=104</guid>
		<description><![CDATA[We had very nice Silverlight sessions this year at the MS days. The well-known speaker and actually very nice guy &#8211; Daron Yöndem, gave fantastic presentations on the new Out-of-browser capabilities in Silverlight 4 and also on the cool stuff about Multi-Touch in both Silverlight and WPF. Me and Emil Stoychev also made a very &#8230; </p><p><a class="more-link block-button" href="http://www.miroslavov.com/?p=104">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>We had very nice Silverlight sessions this year at the <a href="http://www.msbgregistration.com/Lecturers.aspx">MS days</a>. The well-known speaker and actually very nice guy &#8211; <a href="http://daron.yondem.com/default.aspx">Daron Yöndem</a>, gave fantastic presentations on the new Out-of-browser capabilities in Silverlight 4 and also on the cool stuff about Multi-Touch in both Silverlight and WPF. Me and <a href="http://emil.silverlightshow.net/">Emil Stoychev</a> also made a very good presentation, but this was not on &#8220;<em>what can we do with Silverlight</em>&#8220;, but &#8220;<span style="text-decoration: underline;"><strong><em>What we already Did with Silverlight</em></strong></span>&#8220;. It was all about the <a href="http://completit.com/">CompletIT </a>web-site, and it was entirely <em>How To </em> session, including the real examples, problems and solutions we came up with the implementation. I think it was really nice session, with a lot of tips and tricks. Hope the audience think so, as well. <img src='http://www.miroslavov.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
I have some pictures. Big thanks to Daron again &#8211; he is also very good with the camera. <img src='http://www.miroslavov.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img src="http://www.miroslavov.com/wordpress/wp-content/uploads/2010/03/msday3.jpg" alt="Me and Emil @ MS dayl" width="600" height="450" /></p>
<pre style="text-align: left;"><em>Me and Emil @ the start of the session.</em>
</pre>
<p><img src="http://www.miroslavov.com/wordpress/wp-content/uploads/2010/03/msdays2.jpg" alt="Me and Emil @ MS days" width="600" height="450" /></p>
<pre><em><em>We are preparing something that looks great.:) </em></em></pre>
<p><img src="http://www.miroslavov.com/wordpress/wp-content/uploads/2010/03/msdays1.jpg" alt="Me and Emil @ MS day" width="600" height="450" /></p>
<pre><em>Maybe I'm explaining something.</em></pre>
<p><img src="http://www.miroslavov.com/wordpress/wp-content/uploads/2010/04/msdays4.jpg" alt="" /></p>
<p>I hope everybody enjoyed the conference or at least the Silverlight Sessions.</p>
<img src="http://feeds.feedburner.com/~r/DeepWaterSoftware/~4/Kq_PiGGFbEA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.miroslavov.com/?feed=rss2&amp;p=104</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.miroslavov.com/?p=104</feedburner:origLink></item>
		<item>
		<title>Silverlight Animations and the missing Timeline.DesiredFrameRate</title>
		<link>http://feedproxy.google.com/~r/DeepWaterSoftware/~3/jOxiF5ARKkk/</link>
		<comments>http://www.miroslavov.com/?p=60#comments</comments>
		<pubDate>Tue, 23 Mar 2010 12:52:27 +0000</pubDate>
		<dc:creator>Miroslav Miroslavov</dc:creator>
				<category><![CDATA[Silverlight in action]]></category>
		<category><![CDATA[Animations]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.miroslavov.com/?p=60</guid>
		<description><![CDATA[If you ever needed to create very high intensive WPF application  where most of the screen is re-rendered on every frame, you&#8217;ve definitively  been using the Timeline.DesiredFrameRate. Let&#8217;s suppose you have extremely big background images that are moving around in a beautiful manner. If you animate this using the usual Silverlight animation framework (a.k.a Storyboards &#8230; </p><p><a class="more-link block-button" href="http://www.miroslavov.com/?p=60">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>If you ever needed to create very high intensive WPF application  where most of the screen is re-rendered on every frame, you&#8217;ve definitively  been using the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.animation.timeline.desiredframerate.aspx">Timeline.DesiredFrameRate</a>. Let&#8217;s suppose you have extremely big background images that are moving around in a beautiful manner. If you animate this using the usual Silverlight animation framework (a.k.a Storyboards and Animations) you&#8217;ll end up with extremely bad performance and very big CPU usage. You have animations that are on the background and you don&#8217;t want them to utilize the whole CPU time, because  you have more important animations to take care of at the foreground of your app/game.</p>
<p>The actual problem here is that when animating, for example TranslateTransform of an Image, Silverlight engine will try to animate it at MaxFrameRate allowed for the plugin. But this framerate will cost you high frequent redrawing regions and a lot of  CPU time, so you&#8217;ll end up with slow performance for your more important foreground animations.</p>
<p>What we can actually do is to create our own framework, where we can specify for each animation the exact maximum of  allowed framerate (like the holly Timeline.DesiredFrameRate do in WPF).</p>
<h3>Check out the <a href="http://www.miroslavov.com/Silverlight/AnimationFramework/">planes demo </a>and see the performance difference.</h3>
<p>Using the build-in animations the planes and clouds are moving at max framerate, while using our custom framework &#8211; the two clouds are moving at 15fps and the planes are &#8220;flying&#8221; at 24fps. As a result we have about 4 times drop of CPU usage.</p>
<h3>Implementation</h3>
<p>Our animations will be based on the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.compositiontarget.rendering%28VS.95%29.aspx">CompositionTarget.Rendering </a>event, which occurs when the core Silverlight rendering process renders a frame. The idea is to create somehow similar classes like the *Animation but with added FramesPerSecond property. After all having <strong>From, To</strong>, <strong>Duration </strong>and<strong> FramesPerSecond</strong>, with simple math we can calculate:</p>
<ul>
<li>FramesCount &#8211; How many frames will be needed to be &#8220;rendered&#8221; (animate the property)</li>
<li>By <strong>- </strong>The value that will be used for progressing the animation (this actually is done in the implementation of the sub-classes, for example the DoubleAnimation)</li>
</ul>
<h4>Here is the base Animator:</h4>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> Initialize<span style="color: #008000;">&#40;</span>FrameworkElement el<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">element</span> <span style="color: #008000;">=</span> el<span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ticks</span> <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">TicksPerSecond</span> <span style="color: #008000;">/</span> FramesPerSecond<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">totalTicks</span> <span style="color: #008000;">=</span> Duration<span style="color: #008000;">.</span><span style="color: #0000FF;">TimeSpan</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">frames</span> <span style="color: #008000;">=</span> totalTicks <span style="color: #008000;">/</span> ticks<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And for example the TranslateAnimator implementation:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Initialize<span style="color: #008000;">&#40;</span>FrameworkElement element<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Initialize</span><span style="color: #008000;">&#40;</span>element<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
ScaleTransform scale<span style="color: #008000;">;</span>
RotateTransform rotate<span style="color: #008000;">;</span>
SkewTransform skew<span style="color: #008000;">;</span>
&nbsp;
element<span style="color: #008000;">.</span><span style="color: #0000FF;">EnsureTransforms</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">out</span> scale, <span style="color: #0600FF; font-weight: bold;">out</span> rotate, <span style="color: #0600FF; font-weight: bold;">out</span> skew, <span style="color: #0600FF; font-weight: bold;">out</span> translate<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The actual trick is that in the Rendering event handler, we check the time ticks and decide whether, for example to translate the element or not.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> NextFrame<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #6666cc; font-weight: bold;">long</span> now <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>now <span style="color: #008000;">-</span> lastTick <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> ticks<span style="color: #008000;">&#41;</span> <span style="color: #008080; font-style: italic;">//Due to FPS.</span>
<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>BeginTime<span style="color: #008000;">.</span><span style="color: #0000FF;">HasValue</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> now <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> BeginTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span> <span style="color: #008000;">+</span> firstTIck<span style="color: #008000;">&#41;</span>
<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
lastTick <span style="color: #008000;">=</span> now<span style="color: #008000;">;</span>
currentFrame<span style="color: #008000;">++;</span>
&nbsp;
var time <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span> currentFrame<span style="color: #008000;">/</span>frames<span style="color: #008000;">;</span>
&nbsp;
coef <span style="color: #008000;">=</span> EasingFunction <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">?</span> EasingFunction<span style="color: #008000;">.</span><span style="color: #0000FF;">Ease</span><span style="color: #008000;">&#40;</span>time<span style="color: #008000;">&#41;</span> <span style="color: #008000;">:</span> time<span style="color: #008000;">;</span>
&nbsp;
NextFrameOverride<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And the implementation of the real code for it is in the virtual method <strong>NextFrameOverride()</strong>.<br />
The container of all these animators is called <strong>AnimationFrame</strong>. This is where we hook for the CompositionTarget.Rendering event and also the place where  all animators are called to render their next frames.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> CompositionTarget_Rendering<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var animatorPair <span style="color: #0600FF; font-weight: bold;">in</span> animators<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>animatorPair<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">NextFrame</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
finishedItems<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>animatorPair<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var item <span style="color: #0600FF; font-weight: bold;">in</span> finishedItems<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
animators<span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>item<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
SetAnimator<span style="color: #008000;">&#40;</span>item, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
finishedItems<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<h3>And couple of more goodies:</h3>
<ul>
<li>You just attach the needed animator to UIElement and it works (no need to add all the Transforms in your XAML)</li>
<li>It&#8217;s easy to create new animators</li>
<li>There is also CompositeAnimator, that enables you to provide more than one animator for a UIElement</li>
<li>Support for Easing functions</li>
</ul>
<h3><a href="http://www.miroslavov.com/wordpress/wp-content/uploads/2010/03/AnimationFramework.zip">Download Code Here.</a></h3>
<p>There is also an example project comparing the performance of Animators and Animations.</p>
<p>Cheers</p>
<img src="http://feeds.feedburner.com/~r/DeepWaterSoftware/~4/jOxiF5ARKkk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.miroslavov.com/?feed=rss2&amp;p=60</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.miroslavov.com/?p=60</feedburner:origLink></item>
		<item>
		<title>Silverlight.BG Group</title>
		<link>http://feedproxy.google.com/~r/DeepWaterSoftware/~3/2TkE_PLQBN0/</link>
		<comments>http://www.miroslavov.com/?p=5#comments</comments>
		<pubDate>Mon, 15 Feb 2010 18:14:52 +0000</pubDate>
		<dc:creator>Miroslav Miroslavov</dc:creator>
				<category><![CDATA[Bulgarian Community]]></category>
		<category><![CDATA[Speaks]]></category>
		<category><![CDATA[Animations]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.miroslavov.com/?p=5</guid>
		<description><![CDATA[Hi there, At the beginning of March I&#8217;ll have a presentation on the Bulgaria&#8217;s Silverlight Group about the very interesting Animations and Animation Control structures in Silverlight. You can get some more info here. I&#8217;ll upload demo project as soon as possible. Have fun.]]></description>
			<content:encoded><![CDATA[<p>Hi there,</p>
<p>At the beginning of March I&#8217;ll have a presentation on the Bulgaria&#8217;s Silverlight Group about the very interesting Animations and Animation Control structures in Silverlight. You can get some more info <a href="http://silverlight.bg/Events/10-02-15/Silverlight_Animations_and_How_to_Control_them.aspx" target="_blank">here</a>.</p>
<p>I&#8217;ll upload demo project as soon as possible.</p>
<p>Have fun.</p>
<img src="http://feeds.feedburner.com/~r/DeepWaterSoftware/~4/2TkE_PLQBN0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.miroslavov.com/?feed=rss2&amp;p=5</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.miroslavov.com/?p=5</feedburner:origLink></item>
	</channel>
</rss>

