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

<channel>
	<title>Corey Schuman &#187; Silverlight 2.0</title>
	<atom:link href="http://www.85turns.com/tag/silverlight-20/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.85turns.com</link>
	<description>Silverlight Consultant</description>
	<lastBuildDate>Tue, 26 Apr 2011 20:57:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>How to dynamically create animations from C# in Silverlight</title>
		<link>http://www.85turns.com/2008/03/09/how-to-dynamically-create-animations-from-c-in-silverlight/</link>
		<comments>http://www.85turns.com/2008/03/09/how-to-dynamically-create-animations-from-c-in-silverlight/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 05:49:57 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[DoubleAnimation]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 2.0]]></category>
		<category><![CDATA[storyboard]]></category>
		<category><![CDATA[TranslateTransform]]></category>

		<guid isPermaLink="false">http://simplesilverlight.wordpress.com/?p=19</guid>
		<description><![CDATA[So you want to create an animation from managed code. To do this, there is quite a bit of code needed. For every animation there needs to be a new StoryBoard, and unfortunately a StoryBoard can not be reused between objects. (Correction: You can reuse a dynamically created StoryBoard. Make sure to call StoryBoard.Stop() before [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to create an animation from managed code.  To do this, there is quite a bit of code needed.  <strike>For every animation there needs to be a new StoryBoard, and unfortunately a StoryBoard can not be reused between objects</strike>. <font color="#800000">(<b>Correction: </b>You can reuse a dynamically created StoryBoard.  Make sure to call StoryBoard.Stop() before setting the new target.)</font></p>
<p>The approach we are going to take is to animate the TranslateTransforms instead of animating the Canvas.Top and Canvas.Left properties since this is the preferred way of doing animations in WPF.  In the below example we will create a rectangle, attached a set of transforms to the rectangle, and dynamically add animations to the rectangle.</p>
<ol>
<li>Create a Rectangle<br />
<img src="http://simplesilverlight.files.wordpress.com/2008/03/rectangle.png" alt="Create a rectangle code" /></li>
<li>Create a function that returns a RenderTransform.  (I have added more than the TranslateTransform in case you want to access the other transforms at a later time.  It&#8217;s good practices to have them there.)<br />
<img src="http://simplesilverlight.files.wordpress.com/2008/03/transformgroup.png" alt="Function that returns a TransformGroup" /></li>
<li>Create a StoryBoard and add DoubleAnimations for both the X and Y.<br />
<img src="http://simplesilverlight.files.wordpress.com/2008/03/add_storyboard.png" alt="Dynamically add a storyboard and double animations" /></li>
<li>Final product<br />
<img src="http://simplesilverlight.files.wordpress.com/2008/03/finalanimation.png" alt="Final product." /></li>
</ol>
<p>Come back for part 2 and we&#8217;ll animate the Scale and add more than one rectangle.</p>
<p>Edit: In case you don&#8217;t want to brush off your old OCR programs to get the code, here is a <a href="http://silverlight.peterpancomplex.net/zip/animation.zip" title="http://silverlight.peterpancomplex.net/zip/animation.zip">link to the source</a>. <a href="http://www.peakeeng.com/Silverlight/Animation/index.html" title="http://www.peakeeng.com/Silverlight/Animation/index.html">Link to working example</a>.<a href="http://silverlight.peterpancomplex.net/zip/animation.zip" title="http://silverlight.peterpancomplex.net/zip/animation.zip"> </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.85turns.com/2008/03/09/how-to-dynamically-create-animations-from-c-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

