Make sure to read part 1 first!
WP7Contrib offers numerous transitions, these include:
Continuum
The selected item in a list will animate out, and the next page will have the heading animate in. The reverse happens on returning to the original page. This is a great effect if the user is selecting a specific item to view more detail.
Rotate
The page rotates in/out. A bit ostentatious for my tastes.
Slide
There are various slide animations offered, these mimic the kinds of transitions you get with iOS. SlideUp and SlideDown are ideal for popups.
Turnstile
The default transition we all know and love
Turnstile Feather
My personal favourite, and one we’ll see a lot more of in Part 3. This is the same as Turnstile, except it will animate out each element in a list from top to bottom. This is the same effect you see on the phone home screen when you select an app to launch.
If you want to see all of the transitions on offer, download the WP7Contrib source code and open the ‘PageTransitions’ solution within the ‘Spikes’ folder. This provides a demo of all of the transitions on offer within WP7Contrib.
Let’s Play
Let’s try the Turnstile Feather and Continuum transitions out. You’ll need a project with a screen that’s a ListBox, if you don’t have one, download the demo app from the first part of this series. If you want to see the demo right now, click here to download the demo app for part 2.
Go into the code-behind for the page with the ListBox and add the following override:
protected override AnimatorHelperBase GetAnimation(AnimationType animationType, Uri toOrFrom) { return base.GetAnimation(animationType, toOrFrom); }
This is an extremely powerful override that allows you to fully customise the kind of animation used when the page is navigated to or from. The first parameter is the type of animation you need to return. The second parameter is the uri for the page that the user is either navigating to, or navigating from. If ever you’re not sure, use the base implementation which will almost always provide a Turnstile animation. The Turnstile animation is a good fall-back animation, so it’s often wise to handle specific cases yourself, and let the base implementation handle the rest.
Now you could run the app right now and it’ll work, but we want to trigger a Continuum transition on the way out, and a Turnstile Feather animation on the way back in. To do this, we need to tell which animations we want WP7Contrib to use:
protected override AnimatorHelperBase GetAnimation(AnimationType animationType, Uri toOrFrom) { switch (animationType) { case AnimationType.NavigateForwardOut: case AnimationType.NavigateBackwardOut: return this.GetContinuumAnimation(TheListBox, animationType); case AnimationType.NavigateBackwardIn: return new TurnstileFeatherBackwardInAnimator() { ListBox = TheListBox, RootElement = LayoutRoot }; case AnimationType.NavigateForwardIn: return new TurnstileFeatherForwardInAnimator() { ListBox = TheListBox, RootElement = LayoutRoot }; } return base.GetAnimation(animationType, toOrFrom); }
Notice we let WP7Contrib handle any animations we don’t explicitly handle ourselves. This ensures if the app is extended in the future the user experience isn’t unduly affected.
The Continuum animation has three properties, a StoryBoard, RootElement and LayoutRoot. This allows you to customise the animation applied to the selected element, however most of the time the default animation is the correct one. For this reason we get WP7Contrib to create the animation for us by calling GetContinuumAnimation.
The Turnstile Feather animation requires the ListBox you wish to animate and the RootElement. The RootElement in this case is the same element you set as the AnimationContext. You could set a different RootElement if required, but it’s unlikely you’ll ever need to do this.
Now run your app and admire your handy work! You can download a fully functional demo project here.
Want yet more? Click here for part 3.
Hi Dan,
Can you please tell me how to get the Continuum working when you navigate back to the original page? The selected item just appears instantly without animating back into the listbox…
Thanks!
Justin
Hi Justin. Looks like a bug with the transitions themselves. I’ve been meaning to look into this problem but just haven’t had the time recently. If I get a spare few hours I’ll see if I can find the fix and send back up to WP7Contrib so everyone can benefit from the fix.
Also, I have found a couple of issues in your demo project. If I scroll the listbox all the way to the end and then back to the top the gaps between some items increased. Another thing is the Continuum animation doesn’t start from the item’s original position, and if I keep triggering this animation the whole project gets slow…
Justin
Hi Justin. Looks like another bug… For the moment I would recommend ‘feather’ as a stop-gap until the underlying issue is fixed.
Thanks Dan, look forward to seeing them fixed! 🙂
Dan could you please have a look at my post at:
http://wp7contrib.codeplex.com/workitem/10819
i have some weird issues with the turnstyle feather.