Click here to Skip to main content
Click here to Skip to main content

Simple WPF Page Transitions

By , 20 May 2011
 

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

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
BugShowPage( null ) Exception Pinmemberrusvenom13 May '13 - 0:45 
Questionhelp PinmemberMember 95703715 May '13 - 17:35 
GeneralMy vote of 5 Pinmemberjosemartins.grupoma19 Apr '13 - 4:40 
QuestionExcellent Pinmembercodertuhin27 Mar '13 - 6:49 
Questionhow to use multiple windows and navigate backward? [modified] PinmemberCesitar Ps19 Mar '13 - 10:37 
QuestionSlide Function [modified] PinmemberPrasad Dhule10 Mar '13 - 3:59 
GeneralMy vote of 5 Pinmemberjosemartins.grupoma6 Feb '13 - 4:29 
GeneralMy vote of 5 PinmemberAriadnesThread21 Jan '13 - 5:19 
QuestionAnything for .NET 3.5? PinmemberMarc Paliotti6 Sep '12 - 5:16 
GeneralMy vote of 5 Pinmembercotopboy Zhang28 May '12 - 6:23 
QuestionGreat work PinmemberMember 783061516 Mar '12 - 6:53 
BugBug in Slide-function PinmemberBob vd Bergh20 Jan '12 - 2:01 
SuggestionDisable pagetransition? PinmemberBob vd Bergh21 Nov '11 - 5:33 
SuggestionVB version [modified] PinmemberBob vd Bergh18 Nov '11 - 2:38 
SuggestionAlmost perfect ! PinmemberMember 772250924 Jun '11 - 3:13 
QuestionA Cross Fade Transition would rock! Pinmembernatalie7424 Jun '11 - 1:19 
GeneralHow to transition within a particular boundary? PinmemberLap Chan31 May '11 - 13:54 
GeneralCreate a new thread to synchronize it in the next step? Pinmembert0bsen24 May '11 - 9:22 
GeneralIn Windows Forms, this might leak ressources?! Pinmembert0bsen24 May '11 - 8:59 
GeneralNice PinmemberCIDev20 May '11 - 6:03 
Generalvery good! Pinmember428820 May '11 - 5:26 
GeneralMy vote of 5 Pinmembersam.hill20 May '11 - 5:25 
GeneralNice PinmvpSacha Barber20 May '11 - 5:22 

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

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