<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>IRhetoric - Karsten Januszewski   : Action Script</title><link>http://blogs.msdn.com/karstenj/archive/tags/Action+Script/default.aspx</link><description>Tags: Action Script</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Inspired By Flash Math Creativity #3: WPF Flag </title><link>http://blogs.msdn.com/karstenj/archive/2007/03/08/inspired-by-flash-math-creativity-3-wpf-flag.aspx</link><pubDate>Fri, 09 Mar 2007 08:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1842104</guid><dc:creator>karstenj</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/karstenj/comments/1842104.aspx</comments><wfw:commentRss>http://blogs.msdn.com/karstenj/commentrss.aspx?PostID=1842104</wfw:commentRss><description>&lt;P&gt;There is a clever sample up on &lt;A target=_blank href="http://www.friendsofed.com/fmc/FMCv2/FMC.html" mce_href="http://www.friendsofed.com/fmc/FMCv2/FMC.html"&gt;Flash Math Creativity&lt;/A&gt;&amp;nbsp;by &lt;A href="http://www.actionscript.cl/" mce_href="http://www.actionscript.cl"&gt;Lifaros&lt;/A&gt;&amp;nbsp;that fundamentally does 2D morph meshing by chopping up an image into sections and then animating the sections, resulting in the effect of a flag waving.&amp;nbsp; I decided to implement something similar in WPF.&amp;nbsp; When I started thinking about how to chop up something in WPF, I remembered the &lt;A target=_blank href="http://msdn2.microsoft.com/en-us/library/ms771766.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms771766.aspx"&gt;Slide Puzzle&lt;/A&gt; sample from the SDK and I used it the foundation for how to chop, well, anything up in WPF.&amp;nbsp; (If you haven't checked out this sample, definitely do so!) &lt;/P&gt;
&lt;P&gt;In my sample, I only chop up an image, but nothing is stopping you from using this same technique to chop up a video, a document or the UI itself.&amp;nbsp; Once again, I used the custom animation classes to create the animation using &lt;STRONG&gt;Math.Sin&lt;/STRONG&gt;.&amp;nbsp; The slider allows you to modify the intensity of the wave. The result? The UN flag waving in the desert.&amp;nbsp; I'm not sure why.&amp;nbsp; &lt;A href="http://rhizohm.net/download/netfx3/wave.zip" mce_href="http://rhizohm.net/download/netfx3/wave.zip"&gt;Download source&lt;/A&gt; or &lt;A href="http://rhizohm.net/download/netfx3/apps/publish.htm" mce_href="http://rhizohm.net/download/netfx3/apps/publish.htm"&gt;run it&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://wpf.netfx3.com/direct/wave" mce_href="http://wpf.netfx3.com/direct/wave" border="0"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 637px; HEIGHT: 451px" src="http://rhizohm.net/download/netfx3/wave.jpg" width=637 height=451 mce_src="http://rhizohm.net/download/netfx3/wave.jpg"&gt;&lt;/P&gt;
&lt;P&gt;Here's the crux of the code:&lt;/P&gt;
&lt;P&gt;private void Chop()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; stackPanel.Children.Clear();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Image image = (Image)this.Resources["image"];&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BitmapSource bitmap = (BitmapSource)image.Source;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Size size = new Size(bitmap.PixelWidth / 5, bitmap.PixelHeight / 5);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; image.Width = size.Width;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; image.Height = size.Height;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; float edgesize = 1.0f / numCols;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set up viewbox appropriately for each tile.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; numCols; i++)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Rectangle r = new Rectangle();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TranslateTransform t = new TranslateTransform();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.RenderTransform = t;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //this confused me at first!&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.SnapsToDevicePixels = true;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VisualBrush vb = new VisualBrush(image);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //viewboxes are all relative to 1&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vb.Viewbox = new Rect(edgesize * i, 0, edgesize, 1);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vb.ViewboxUnits = BrushMappingMode.RelativeToBoundingBox;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.Fill = vb;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.Height = image.Height;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.Width = image.Width / numCols;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CircleAnimation ca = new CircleAnimation();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ca.Direction = CircleAnimation.DirectionEnum.YDirection;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ca.Radius = slider.Value;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ca.Duration = TimeSpan.FromSeconds(1);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ca.BeginTime = TimeSpan.FromMilliseconds(i * 10);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ca.RepeatBehavior = RepeatBehavior.Forever;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t.BeginAnimation(TranslateTransform.YProperty, ca);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stackPanel.Children.Add(r);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1842104" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/karstenj/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/Action+Script/default.aspx">Action Script</category></item><item><title>Inspired By Flash Math Creativity: WPF Flowers</title><link>http://blogs.msdn.com/karstenj/archive/2007/02/16/inspired-by-flash-math-creativity-wpf-flowers.aspx</link><pubDate>Fri, 16 Feb 2007 20:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1690605</guid><dc:creator>karstenj</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/karstenj/comments/1690605.aspx</comments><wfw:commentRss>http://blogs.msdn.com/karstenj/commentrss.aspx?PostID=1690605</wfw:commentRss><description>&lt;P&gt;&lt;A href="http://winfx.members.winisp.net/flowers/"&gt;&lt;IMG style="MARGIN: 0px 10px 10px" src="http://winfx.members.winisp.net/images/flower.jpg" align=right border=0&gt;&lt;/A&gt;I've recently picked up a great book called &lt;A class="" href="http://www.friendsofed.com/fmc/FMCv2/FMC.html" target=_blank mce_href="http://www.friendsofed.com/fmc/FMCv2/FMC.html"&gt;Flash Math Creativity&lt;/A&gt;.&amp;nbsp; I been inspired by some of the techniques it outlines and have played around with similar ideas in WPF.&amp;nbsp; The exercise has been a fruitful one, in that I'm making some pleasing computer art while also learning about the differences between Action Script animation and WPF animation.&amp;nbsp; The first one I played with is flowers, inspired by the work of &lt;A class="" href="http://www.glenrhodes.com/" target=_blank mce_href="http://www.glenrhodes.com "&gt;Glen Rhodes&lt;/A&gt;, which is actually featured on the cover of the book.&amp;nbsp; You can &lt;A class="" href="http://winfx.members.winisp.net/flowers/" target=_blank mce_href="http://winfx.members.winisp.net/flowers/"&gt;see the results here&lt;/A&gt; and &lt;A class="" href="http://winfx.members.winisp.net/flowers.zip" mce_href="http://winfx.members.winisp.net/flowers.zip"&gt;download the code here&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;The first flower, which has no animation, is pretty simple. I just create 125 rectangles with a fill using a DrawingBrush I created in Blend.&amp;nbsp; I place each of the petals on the "stage", which in the case is a &lt;STRONG&gt;Grid&lt;/STRONG&gt;.&amp;nbsp; I use &lt;STRONG&gt;Grid&lt;/STRONG&gt; instead of &lt;STRONG&gt;Canvas&lt;/STRONG&gt; so that I get the goodness of the WPF layout engine for free without having to handle any positioning of the rectangles.&amp;nbsp; I then tranform the rotation and scale of each one to create the flower effect.&amp;nbsp; I also swap the ZIndex so that the large petals are in back and the smaller ones are in front. &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;void OnLoaded(object sender, EventArgs e)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int r = 0;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; double s = 0;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i=0; i &amp;lt; 125; i++)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Rectangle rect = new Rectangle();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rect.Width = 50;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rect.Height = 50;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rect.Fill = (DrawingBrush)this.FindResource("petal");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TransformGroup tg = new TransformGroup();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s += .01;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ScaleTransform st = new ScaleTransform(s * s * s + .1, s * s * s + .1);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r += 27;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RotateTransform rt = new RotateTransform(r);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tg.Children.Add(st);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tg.Children.Add(rt);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rect.RenderTransform = tg;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.SetZIndex(rect, -i);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stage.Children.Add(rect);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;&lt;A href="http://winfx.members.winisp.net/flowers/"&gt;&lt;IMG style="MARGIN: 0px 10px 10px" src="http://winfx.members.winisp.net/images/flower2.jpg" align=left border=0&gt;&lt;/A&gt;Where things get a little more interesting is when it comes to animating the flower. In Action Script, this kind of dynamic animation is handled through the very convenient &lt;STRONG&gt;onEnterFrame&lt;/STRONG&gt;.&amp;nbsp; This handler provides a per-frame callback for each individual movie clip, in which a function can be wired up.&amp;nbsp; There is no equivalent in WPF such that you get a per-frame callback &lt;EM&gt;for each element&lt;/EM&gt;.&amp;nbsp; The&amp;nbsp;closest thing to this concept is the &lt;STRONG&gt;CompositionTarget.Rendering&lt;/STRONG&gt; handler, which gets called per-frame for the entire tree (or page or stage, if you will.) &lt;/P&gt;
&lt;P&gt;It is possible to find each element you are looking for when this event gets fired and achieve a similar effect to &lt;STRONG&gt;onEnterFrame&lt;/STRONG&gt;.&amp;nbsp; I did just this in Page3.xaml, which ends up adding the following in addition to the loaded method:&lt;/P&gt;
&lt;P mce_keep="true"&gt;void CompositionTarget_Rendering(object sender, EventArgs e)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (UIElement uie in stage.Children)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TransformGroup tg = uie.RenderTransform as TransformGroup;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ScaleTransform st = tg.Children[0] as ScaleTransform;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (st.ScaleX &amp;gt; -3)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; st.ScaleX -= .1;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see how I end up having to walk the tree, extracting the children and then acting on the children.&amp;nbsp; While this works, there are several disadvantages to this methodology.&amp;nbsp; First, having to figure out the animation for every UI element within a single callback has the potential to get quite unwieldy.&amp;nbsp; Second, using this method means we don't get all of the goodness of the WPF animation system, things like frame rate indepence, timelines, storyboards, repeat behaviors, autoreverse, etc.&amp;nbsp; So, let's see what this animation would look like using the WPF animation system:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://winfx.members.winisp.net/flowers/"&gt;&lt;IMG style="MARGIN: 0px 10px 10px" src="http://winfx.members.winisp.net/images/flower3.jpg" align=right border=0&gt;&lt;/A&gt;void Page2_Loaded(object sender, RoutedEventArgs e)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int r = 0;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; double s = 0;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DoubleAnimation d = new DoubleAnimation(-3, new Duration(TimeSpan.FromSeconds(2)));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; d.AutoReverse = true;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; d.RepeatBehavior = RepeatBehavior.Forever;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; 125; i++)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Rectangle rect = new Rectangle();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rect.Width = 50;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rect.Height = 50;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rect.Opacity = .5;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rect.Fill = (DrawingBrush)this.FindResource("petal2");&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TransformGroup tg = new TransformGroup();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s += .01;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ScaleTransform st = new ScaleTransform(s * s * s + .1, s * s * s + .1);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r += 27;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RotateTransform rt = new RotateTransform(r);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tg.Children.Add(st);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tg.Children.Add(rt);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rect.RenderTransform = tg;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.SetZIndex(rect, -i);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; st.BeginAnimation(ScaleTransform.ScaleXProperty, d);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stage.Children.Add(rect);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;With this code, I get to wire up an animation to each element -- in fact I'm wiring up the same animation, which simply animates the scale.&amp;nbsp; I get to use some of the features of the animation system, like AutoReverse and RepeatBehaviors.&amp;nbsp; And, I'm letting WPF calculate the timing instead of me doing it per-frame.&amp;nbsp; Much nicer, methinks.&lt;/P&gt;
&lt;P&gt;Those seasoned with the WPF samples can probably deduce where I derived the harness you toggle between the different animations. I took the basic idea from &lt;A class="" href="http://wpf.netfx3.com/files/folders/controls/entry8196.aspx" target=_blank mce_href="http://wpf.netfx3.com/files/folders/controls/entry8196.aspx"&gt;Kevin Moore's Bag-o-Tricks&lt;/A&gt; and then added the fading between frames from the custom frame in the WPF Feature Fest sample.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I'm also now pointing all my WPF samples to an HTML page which checks to see if you have the framework installed and directs you to where you get it if you don't.&amp;nbsp; I took this from the Windows SDK and modified to to auto-redirect if .NET 3.0 is installed.&amp;nbsp; It is included in the source.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1690605" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/karstenj/archive/tags/Windows+Presentation+Foundation+_2800_Avalon_2900_/default.aspx">Windows Presentation Foundation (Avalon)</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/Action+Script/default.aspx">Action Script</category></item></channel></rss>