Click here to Skip to main content
15,879,095 members
Articles / Desktop Programming / WPF

Simple WPF Page Transitions

Rate me:
Please Sign up or sign in to vote.
4.92/5 (60 votes)
20 May 2011CPOL2 min read 215K   19.3K   104   61
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:

XML
<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:

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


Written By
Architect
United States United States
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.

Comments and Discussions

 
QuestionSlide Function Pin
Prasad Dhule10-Mar-13 3:59
Prasad Dhule10-Mar-13 3:59 
GeneralMy vote of 5 Pin
Schrodinger's Box6-Feb-13 4:29
Schrodinger's Box6-Feb-13 4:29 
GeneralMy vote of 5 Pin
AriadnesThread21-Jan-13 5:19
AriadnesThread21-Jan-13 5:19 
QuestionAnything for .NET 3.5? Pin
Marc Paliotti6-Sep-12 5:16
Marc Paliotti6-Sep-12 5:16 
AnswerRe: Anything for .NET 3.5? Pin
Aron Weiler15-Oct-12 12:42
Aron Weiler15-Oct-12 12:42 
GeneralMy vote of 5 Pin
Ruifeng Zhang28-May-12 6:23
Ruifeng Zhang28-May-12 6:23 
QuestionGreat work Pin
Member 783061516-Mar-12 6:53
Member 783061516-Mar-12 6:53 
BugBug in Slide-function Pin
Bob vd Bergh20-Jan-12 2:01
Bob vd Bergh20-Jan-12 2:01 
Just to let you know, there is a bug in the Slide and SlideAndFade option.

Open the project in Visual Studio and run it. Select the Slide option. Press "Next Page". It slides just fine. Resize the windowwidth about 50% or more and press "Next Page" again. You will see the inner page disappear after it slided 50%. Samething happens with the SladeAndFade-option, although less noticeable.
With a white background and a white inner you hardly see it, but with other backgroundcolors it is very noticeable. Hope you can fix this.

Other than that: my hat's off to you sir! Smile | :)
SuggestionDisable pagetransition? Pin
Bob vd Bergh21-Nov-11 5:33
Bob vd Bergh21-Nov-11 5:33 
SuggestionVB version Pin
Bob vd Bergh18-Nov-11 2:38
Bob vd Bergh18-Nov-11 2:38 
QuestionRe: VB version Pin
chofillo16-Apr-12 8:48
chofillo16-Apr-12 8:48 
GeneralRe: VB version Pin
WolfmanLee16-Jun-12 2:35
WolfmanLee16-Jun-12 2:35 
GeneralRe: VB version Pin
atzdgreat28-Jun-12 1:41
atzdgreat28-Jun-12 1:41 
GeneralRe: VB version Pin
Santo Adzelito24-Oct-12 2:50
Santo Adzelito24-Oct-12 2:50 
GeneralRe: VB version Pin
woonhow22-Apr-15 5:06
woonhow22-Apr-15 5:06 
GeneralRe: VB version Pin
User 1230168825-May-17 23:35
User 1230168825-May-17 23:35 
GeneralRe: VB version Pin
User 1230168825-May-17 23:38
User 1230168825-May-17 23:38 
SuggestionAlmost perfect ! Pin
Member 772250924-Jun-11 3:13
Member 772250924-Jun-11 3:13 
GeneralRe: Almost perfect ! Pin
paulot2130-Jun-11 1:56
paulot2130-Jun-11 1:56 
QuestionA Cross Fade Transition would rock! Pin
Bastien Neyer24-Jun-11 1:19
Bastien Neyer24-Jun-11 1:19 
GeneralHow to transition within a particular boundary? Pin
Lap Chan31-May-11 13:54
Lap Chan31-May-11 13:54 
GeneralRe: How to transition within a particular boundary? Pin
Aron Weiler31-May-11 13:59
Aron Weiler31-May-11 13:59 
GeneralCreate a new thread to synchronize it in the next step? Pin
t0bsen24-May-11 9:22
t0bsen24-May-11 9:22 
GeneralRe: Create a new thread to synchronize it in the next step? Pin
Aron Weiler24-May-11 11:40
Aron Weiler24-May-11 11:40 
GeneralRe: Create a new thread to synchronize it in the next step? Pin
t0bsen24-May-11 11:43
t0bsen24-May-11 11:43 

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.