Click here to Skip to main content
15,881,281 members
Articles / .NET / .NET4.5
Tip/Trick

WPF Animation

Rate me:
Please Sign up or sign in to vote.
4.25/5 (4 votes)
18 Sep 2012CPOL 29.4K   9   4
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.

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

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

C#
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. 

C#
Storyboard storyboard = new Storyboard();

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

C#
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.

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NIC
India India
I have more then 5 years of experience in the software development sectors with more then 15 softwares in C#, WPF, SQL SERVER, WCF, LINQ, intel perceptual computing sdk, digital signature, snmp.

Comments and Discussions

 
QuestionWhere is source code to download Pin
Tridip Bhattacharjee29-May-14 21:37
professionalTridip Bhattacharjee29-May-14 21:37 
SuggestionPerfect Pin
Vinicius.mr199322-Feb-13 1:53
Vinicius.mr199322-Feb-13 1:53 
GeneralRe: Perfect Pin
Anup Kumar Verma22-Feb-13 3:56
Anup Kumar Verma22-Feb-13 3:56 
QuestionNot an article. Pin
_Amy18-Sep-12 1:30
professional_Amy18-Sep-12 1:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.