Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

WPF Animation

0.00/5 (No votes)
18 Sep 2012 1  
Taskbar Notification like animation in WPF from code behind

Introduction

This article discusses how to apply animation on the WPF window load event to give notification bar like effect. 

Background

In this article I am using the DoubleAnimation and StoryBoard Class of the WPF for creating sliding window animation.

Using the code

Firstly, we have to set window at the left bottom of the screen.

//
// this.Left = SystemParameters.PrimaryScreenWidth  - this.Width;
// 

Now, we have to create DoubleAnimation to change the apparence of the windows at runtime.

using using System.Windows.Media.Animation;
DoubleAnimation doubleanimation = new DoubleAnimation();
doubleanimation .To = SystemParameters.PrimaryScreenHeight - (this.Height+50);
doubleanimation .From = SystemParameters.PrimaryScreenHeight;
doubleanimation .AutoReverse = false;

and now create a StoryBoard object. 

Storyboard storyboard = new Storyboard();

Next step is to  set target and targetproperty of the StoryBoard.

Storyboard.SetTarget(doubleanimation,this);
Storyboard.SetTargetProperty(doubleanimation, new PropertyPath(Window.TopProperty));

Here SetTarget and  SetTargetProperty are the static methods of the Storyboard  and Window.TopProperty  is the property which I use to slide the window from bottom to up in a animated manner. 

Now, just add doubleanimation to storyboard and start animation.

storyboard.Children.Add(doubleanimation);
storyboard.Begin(this);

Points of Interest 

We can use any property of the window to generate different type of animations.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here