<?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>Eclipsed4utoo&#039;s Blog&#187; storyboard</title>
	<atom:link href="http://eclipsed4utoo.com/blog/tag/storyboard/feed/" rel="self" type="application/rss+xml" />
	<link>http://eclipsed4utoo.com/blog</link>
	<description>Not Your Ordinary Programmer</description>
	<lastBuildDate>Thu, 08 Sep 2011 17:09:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>WPF &#8211; Create Animation Programmatically</title>
		<link>http://eclipsed4utoo.com/blog/wpf-create-animation-programmatically/</link>
		<comments>http://eclipsed4utoo.com/blog/wpf-create-animation-programmatically/#comments</comments>
		<pubDate>Thu, 20 May 2010 22:00:48 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[storyboard]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=332</guid>
		<description><![CDATA[This is a short code snippet on creating an animation in WPF through code. In my Twitter app that I have been working on, I was recently doing some optimizations.  When I first did the app, I was new to WPF and knew nothing about animations.  After spending time in Silverlight, I used that knowledge [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short code snippet on creating an animation in WPF through code.</p>
<p>In my <a href="http://eclipsed4utoo.com/blog/twiteclipse-twitter-desktop-client/" target="_blank">Twitter</a> app that I have been working on, I was recently doing some optimizations.  When I first did the app, I was new to WPF and knew nothing about animations.  After spending time in Silverlight, I used that knowledge to do some animations in WPF.</p>
<p>I wanted to do simple &#8220;fade-in&#8221; and &#8220;fade-out&#8221; animations when removing tweets from view and adding new tweets to the view.   And being the person that I am, I like doing this stuff in code.  While I like XAML a lot, I still like writing the code.  So here is how to do an animation that changes the Opacity property programmatically.</p>
<pre class="brush: csharp;">
// because I am doing these as extension methods, they
//   will be available to all UIElement objects, which are
//   basically all controls that can be added to the GUI
public static class ControlAnimationExtensionMethods
{
    public static void FadeIn(this UIElement targetControl)
    {
        DoubleAnimation fadeInAnimation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(1.5)));
        Storyboard.SetTarget(fadeInAnimation, targetControl);
        Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath(UIElement.OpacityProperty));
        Storyboard sb = new Storyboard();
        sb.Children.Add(fadeInAnimation);
        sb.Begin();
    }

    public static void FadeOut(this UIElement targetControl)
    {
        DoubleAnimation fadeInAnimation = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(1.5)));
        Storyboard.SetTarget(fadeInAnimation, targetControl);
        Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath(UIElement.OpacityProperty));
        Storyboard sb = new Storyboard();
        sb.Children.Add(fadeInAnimation);
        sb.Begin();
    }
}
</pre>
<p>This code is useful when dynamically creating controls that you want to do animations on.</p>
<pre class="brush: csharp;">
TextBlock tb = new TextBlock();
tb.Name = &quot;textBlock1&quot;;
// set more property values

tb.FadeIn();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/wpf-create-animation-programmatically/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

