Click here to Skip to main content
Licence CPOL
First Posted 20 May 2011
Views 15,933
Downloads 2,445
Bookmarked 52 times

Simple WPF Page Transitions

By | 20 May 2011 | Article
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)

About the Author

Aron Weiler

Technical Lead
CareFusion
United States United States

Member

I just looooove software.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionGreat work PinmemberMember 78306156:53 16 Mar '12  
BugBug in Slide-function PinmemberBob vd Bergh2:01 20 Jan '12  
SuggestionDisable pagetransition? PinmemberBob vd Bergh5:33 21 Nov '11  
SuggestionVB version [modified] PinmemberBob vd Bergh2:38 18 Nov '11  
QuestionRe: VB version Pinmemberchofillo8:48 16 Apr '12  
SuggestionAlmost perfect ! PinmemberMember 77225093:13 24 Jun '11  
GeneralRe: Almost perfect ! Pinmemberpaulot211:56 30 Jun '11  
QuestionA Cross Fade Transition would rock! Pinmembernatalie741:19 24 Jun '11  
GeneralHow to transition within a particular boundary? PinmemberLap Chan13:54 31 May '11  
GeneralRe: How to transition within a particular boundary? PinmemberAron Weiler13:59 31 May '11  
GeneralCreate a new thread to synchronize it in the next step? Pinmembert0bsen9:22 24 May '11  
GeneralRe: Create a new thread to synchronize it in the next step? PinmemberAron Weiler11:40 24 May '11  
GeneralRe: Create a new thread to synchronize it in the next step? Pinmembert0bsen11:43 24 May '11  
GeneralIn Windows Forms, this might leak ressources?! Pinmembert0bsen8:59 24 May '11  
GeneralRe: In Windows Forms, this might leak ressources?! PinmemberAron Weiler11:30 24 May '11  
GeneralNice PinmemberCIDev6:03 20 May '11  
Generalvery good! Pinmember42885:26 20 May '11  
GeneralMy vote of 5 Pinmembersam.hill5:25 20 May '11  
GeneralNice PinmvpSacha Barber5:22 20 May '11  

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

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

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