Click here to Skip to main content
15,561,907 members
Articles / Desktop Programming / WPF
Article
Posted 20 May 2011

Stats

203K views
19.2K downloads
104 bookmarked

Simple WPF Page Transitions

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

 
QuestionWhat if i have my button on my Page? Pin
Ralph L. Villasoto15-Aug-13 18:32
Ralph L. Villasoto15-Aug-13 18:32 
AnswerRe: What if i have my button on my Page? Pin
Randi Assalaarachchi26-Jan-16 23:40
Randi Assalaarachchi26-Jan-16 23:40 
SuggestionI added 3 transitions type PinPopular
pat_vrs15-Aug-13 10:43
pat_vrs15-Aug-13 10:43 
GeneralMy vote of 5 Pin
mjcg1230-Jul-13 10:45
mjcg1230-Jul-13 10:45 
BugShowPage( null ) Exception Pin
rusvenom13-May-13 1:45
rusvenom13-May-13 1:45 
Questionhelp Pin
Member 95703715-May-13 18:35
Member 95703715-May-13 18:35 
GeneralMy vote of 5 Pin
Schrodinger's Box19-Apr-13 5:40
Schrodinger's Box19-Apr-13 5:40 
QuestionExcellent Pin
codertuhin27-Mar-13 7:49
codertuhin27-Mar-13 7:49 
Excellent Post...Very useful...

Thanks so much...
Questionhow to use multiple windows and navigate backward? Pin
Cesitar Ps19-Mar-13 11:37
Cesitar Ps19-Mar-13 11:37 
QuestionSlide Function Pin
Prasad Dhule10-Mar-13 4:59
Prasad Dhule10-Mar-13 4:59 
GeneralMy vote of 5 Pin
Schrodinger's Box6-Feb-13 5:29
Schrodinger's Box6-Feb-13 5:29 
GeneralMy vote of 5 Pin
AriadnesThread21-Jan-13 6:19
AriadnesThread21-Jan-13 6:19 
QuestionAnything for .NET 3.5? Pin
Marc Paliotti6-Sep-12 6:16
Marc Paliotti6-Sep-12 6:16 
AnswerRe: Anything for .NET 3.5? Pin
Aron Weiler15-Oct-12 13:42
Aron Weiler15-Oct-12 13:42 
GeneralMy vote of 5 Pin
Ruifeng Zhang28-May-12 7:23
Ruifeng Zhang28-May-12 7:23 
QuestionGreat work Pin
Member 783061516-Mar-12 7:53
Member 783061516-Mar-12 7:53 
BugBug in Slide-function Pin
Bob vd Bergh20-Jan-12 3:01
Bob vd Bergh20-Jan-12 3:01 
SuggestionDisable pagetransition? Pin
Bob vd Bergh21-Nov-11 6:33
Bob vd Bergh21-Nov-11 6:33 
SuggestionVB version Pin
Bob vd Bergh18-Nov-11 3:38
Bob vd Bergh18-Nov-11 3:38 
QuestionRe: VB version Pin
chofillo16-Apr-12 9:48
chofillo16-Apr-12 9:48 
GeneralRe: VB version Pin
WolfmanLee16-Jun-12 3:35
WolfmanLee16-Jun-12 3:35 
GeneralRe: VB version Pin
atzdgreat28-Jun-12 2:41
atzdgreat28-Jun-12 2:41 
GeneralRe: VB version Pin
Santo Adzelito24-Oct-12 3:50
Santo Adzelito24-Oct-12 3:50 
GeneralRe: VB version Pin
woonhow22-Apr-15 6:06
woonhow22-Apr-15 6:06 
GeneralRe: VB version Pin
Baki TANRISEVEN26-May-17 0:35
Baki TANRISEVEN26-May-17 0:35 

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.