Click here to Skip to main content
12,621,744 members (37,612 online)
Click here to Skip to main content
Add your own
alternative version

Stats

113.8K views
15.1K downloads
97 bookmarked
Posted

Simple WPF Page Transitions

, 20 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
WPF UserControl enabling simple page transitions, such as slide, grow, spin, etc.

Introduction / Background

I have a little side project that I am working on which has multiple pages of information that need to be displayed, and I wanted a slicker way to transition between pages (UserControls) than just popping them into and out of existence (bad for the eyes).

My desire was to have better looking transitions, and this led me to develop a very simple control library with several animations built in for more elegant page switches.

The following page transition types are currently included in this version of the control:

  • Fade
  • Slide
  • SlideAndFade
  • Grow
  • GrowAndFade
  • Flip
  • FlipAndFade
  • Spin
  • SpinAndFade

The control itself is very simple... it consists of a UserControl (PageTransition) which contains all of the translation logic. Inside this control, there are several animations in the UserControl.Resources tag, defining all of the available animations. There is also an enum (PageTransitionType) which is mapped as a DependencyProperty that defines which animations are available to the users of the control.

spinfade.png

Using the Code

Using the PageTransition control is easy... you just drop the control onto your WPF window (or type it in, using the XAML editor), which will then look something like this:

<pageTransitions:PageTransition Name="pageTransition" Margin="25" TransitionType="Fade" />

Remember to set the TransitionType property to one of the available values (in the list above), which will determine the type of animation that is displayed.

Don't forget to add the namespace of the WpfPageTransitions project/class in your window/control declaration!

At this point, you can make a page change by referencing the PageTransition control on your window and doing something like this in your code-behind:

NewPage newPage = new NewPage();
pageTransition.ShowPage(newPage);   

Points of Interest

An interesting quirk that I came across when doing the animation for the slide-in/out is that using the TranslateTransform for sliding controls in and out of the window area doesn't appear to work correctly. I wasn't really looking for the slide-in/out feature, so I kind of skipped investigating the issue... If anyone has a sample they want to post of using TranslateTransform to move the control around, that would be great.

History

First revision.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Aron Weiler
Technical Lead CareFusion
United States United States
I just looooove software.

Check out my technical blog here: The Fyslexic Duck. You can find most of what I've put on CodeProject there, plus some additional technical articles.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
AnswerRe: Anything for .NET 3.5? Pin
Aron Weiler15-Oct-12 13:42
memberAron Weiler15-Oct-12 13:42 
GeneralMy vote of 5 Pin
cotopboy Zhang28-May-12 7:23
membercotopboy Zhang28-May-12 7:23 
QuestionGreat work Pin
Member 783061516-Mar-12 7:53
memberMember 783061516-Mar-12 7:53 
BugBug in Slide-function Pin
Bob vd Bergh20-Jan-12 3:01
memberBob vd Bergh20-Jan-12 3:01 
SuggestionDisable pagetransition? Pin
Bob vd Bergh21-Nov-11 6:33
memberBob vd Bergh21-Nov-11 6:33 
SuggestionVB version Pin
Bob vd Bergh18-Nov-11 3:38
memberBob vd Bergh18-Nov-11 3:38 
QuestionRe: VB version Pin
chofillo16-Apr-12 9:48
memberchofillo16-Apr-12 9:48 
GeneralRe: VB version Pin
WolfmanLee16-Jun-12 3:35
memberWolfmanLee16-Jun-12 3:35 
I would love this in VB.Net format too. Is it still available? Thanks!
GeneralRe: VB version Pin
atzdgreat28-Jun-12 2:41
memberatzdgreat28-Jun-12 2:41 
GeneralRe: VB version Pin
Santo Adzelito24-Oct-12 3:50
memberSanto Adzelito24-Oct-12 3:50 
GeneralRe: VB version Pin
woonhow22-Apr-15 6:06
memberwoonhow22-Apr-15 6:06 
SuggestionAlmost perfect ! Pin
Member 772250924-Jun-11 4:13
memberMember 772250924-Jun-11 4:13 
GeneralRe: Almost perfect ! Pin
paulot2130-Jun-11 2:56
memberpaulot2130-Jun-11 2:56 
QuestionA Cross Fade Transition would rock! Pin
natalie7424-Jun-11 2:19
membernatalie7424-Jun-11 2:19 
GeneralHow to transition within a particular boundary? Pin
Lap Chan31-May-11 14:54
memberLap Chan31-May-11 14:54 
GeneralRe: How to transition within a particular boundary? Pin
Aron Weiler31-May-11 14:59
memberAron Weiler31-May-11 14:59 
GeneralCreate a new thread to synchronize it in the next step? Pin
t0bsen24-May-11 10:22
membert0bsen24-May-11 10:22 
GeneralRe: Create a new thread to synchronize it in the next step? Pin
Aron Weiler24-May-11 12:40
memberAron Weiler24-May-11 12:40 
GeneralRe: Create a new thread to synchronize it in the next step? Pin
t0bsen24-May-11 12:43
membert0bsen24-May-11 12:43 
GeneralIn Windows Forms, this might leak ressources?! Pin
t0bsen24-May-11 9:59
membert0bsen24-May-11 9:59 
GeneralRe: In Windows Forms, this might leak ressources?! Pin
Aron Weiler24-May-11 12:30
memberAron Weiler24-May-11 12:30 
GeneralNice Pin
CIDev20-May-11 7:03
memberCIDev20-May-11 7:03 
Generalvery good! Pin
428820-May-11 6:26
member428820-May-11 6:26 
GeneralMy vote of 5 Pin
sam.hill20-May-11 6:25
membersam.hill20-May-11 6:25 
GeneralNice Pin
Sacha Barber20-May-11 6:22
mvpSacha Barber20-May-11 6:22 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 20 May 2011
Article Copyright 2011 by Aron Weiler
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid