In my most recent article, I describe how to use code modify an animation’s properties. Earlier this year, I wrote a similar article on how to do accomplish the same task where you write some code to modify an animation’s properties. The reason for two articles is not because I have a lot of free time (Fable II and Gears of War 2 take care of that), but it is because of differences between Silverlight and WPF.

For the most part, the differences between Silverlight and WPF are so minor that just adding a note is good enough – especially in areas where WPF and Silverlight are largely identical. The word on the street is that Silverlight is a subset of WPF, and most things that work in Silverlight should work in WPF as well. What I am going to explain in this post, is that the opposite holds true as well. There are cases where Silverlight has more functionality than WPF and going from Silverlight to WPF will not work.

Referencing a named Keyframe
In the context of the two articles in question, the major difference between WPF and Silverlight has to do with being able to reference a named keyframe. To give you a quick refresh, a Storyboard is a container for one or more animations, and each animation is a container for one or more keyframes. A keyframe is pretty much at the bottom of your tree when it comes to animation in WPF and Silverlight.

Despite it’s low standing amongst its Storyboard and Animation peers, in Silverlight, you can access a keyframe directly by simply referencing its name:

keyframeName.Value =my custom value”;

In WPF, though, even if you give your keyframe a name, you can’t access it as directly as you can in Silverlight. Accessing a property of a keyframe in a WPF animation literally requires you writing code that traverses your Storyboard->Animation->Keyframe tree:

//Storyboard
Storyboard currentStoryboard = Window.Resources["Storyboard1"] as Storyboard;
 
//Animation
DoubleAnimationUsingKeyFrames animation = currentStoryboard.Children[0] as DoubleAnimationUsingKeyFrames;
 
//Keyframe
SplineDoubleKeyFrame keyframe = animation.KeyFrames[0] as SplineDoubleKeyFrame;
keyframe.Value = 100;

Notice that in the WPF case, I access our storyboard first, then access its animation, and then I access its keyframe.

As you can clearly see, the Silverlight approach is quite nice. Besides it providing direct access to the keyframe and its properties, I gain some flexibility where modifications to my animation will not cause my code to fail as long as the keyframe’s name I am referencing still exists.

Another advantage is that this frees me from having to think too much about my animation’s under-the-hood details. In order to traverse down my animation, I had to look at my XAML and extract the type of animation and keyframe I was dealing with. Not all animations will use a DoubleAnimationUsingKeyframes and SplineDoubleKeyFrame as their animation and keyframe types, and you shouldn’t have to spend time keeping track of all these types.

After all, Mistyping (ha!) in these cases is not a good idea.

Cheers!
Kirupa

View Comments to “Modifying Animation Properties – Silverlight and WPF”

  1. wonder file Says:

    Thanks for your concepts. One thing I’ve got noticed is always that banks plus financial institutions really know the spending patterns of consumers while also understand that a lot of people max away their credit cards around the trips. They correctly take advantage of this particular fact and start flooding your own inbox plus snail-mail box with hundreds of no interest APR credit cards offers just after the holiday season ends. Knowing that if you’re like 98% in the American open public, you’ll leap at the possible opportunity to consolidate credit debt and transfer balances for 0 APR credit cards.

  2. text link ads Says:

    Daniel, yea I can see text link ads what you did there. I actually liked that part, text link ads but hehe I’m not that harsh like my dad with these things. He at all times text link ads tells me crazy stories again in the day and calls me a loser. I assume it’s time I transfer out of my parents’ basement LOL. Aaanyways, text link ads what about you? text link ads what does text link ads your dad assume xD” Anyway, in my language, text link ads there usually are not much text link ads good source like this.

  3. seo packages Says:

    I’ve been making an attempt to seo packages Gain entry to this web site for a while. I used to seo packages be utilizing IE then once I tried Firefox, it labored just effective? Just wanted to bring this to your attention. This is actually good blog. I have a bunch myself. I actually admire your design. I know that is off seo packages matter however,did you make seo packages this design yourself,or buy from someplace? Anyway, in my language, there are not seo packages much good supply like this.

  4. linkwheel Says:

    Hello, I saw a three linkwheel diet of your attention-grabbing posted posts and needed to ask in the event you would be interested in reciprocal pages? Crew have weblog about alexis linkwheel diet texas ass! Anyway, in my language linkwheel diet, there usually are not much good supply like this.

  5. aassddaag Says:

    My wife and i felt really peaceful that Michael could finish up his web research through your ideas he came across through the web pages. It is now and again perplexing to simply be giving freely ideas many others could have been trying to sell. So we understand we have you to appreciate for this. The most important explanations you made, the straightforward site menu, the relationships your site assist to promote – it’s got all exceptional, and it’s leading our son in addition to our family recognize that this situation is amusing, and that’s truly vital. Thanks for the whole thing!

  6. como conquistar a una mujer Says:

    Very useful post. I think this can make me some idea. And i wish there was a post about wireless phone plans.

  7. pan card Says:

    I am glad that I have observed this blog. Ultimately anything not a crap, which we understand quite usually. The web site is lovingly maintained and up to date. So it really should be, thank you for this welcome transform.

  8. Trampki Allegro Says:

    You actually make it seem so easy with your presentation but I find this matter to be really something that I think I would never understand. It seems too complex and extremely broad for me. I am looking forward for your next post, I’ll try to get the hang of it!

  9. pokiereszowany.com Says:

    It is actually a great and useful piece of info. I’m glad that you just shared this useful info with us. Please keep us informed like this. Thanks for sharing.

  10. Affordable SEO packages Says:

    As the trendy
    day business have grown to a greater expand many of the work is
    completed through the internet. One of the best technique which provides
    a faster & better web solution could be the search engine
    optimization. This technique helps the web designers to improve the
    quality & visibility of the webpage.

  11. systemy grzewcze ³ódŸ Says:

    Everyone loves what you guys are up too. This kind of clever work and coverage! Keep up the amazing works guys I’ve you guys to blogroll.

Leave a Reply

blog comments powered by Disqus