Tag Archives: transition

Adding transitions to a MVVM based dialog

In my last blog post about MVVM, I showed how it is natural to build a common WPF dialog using DataBinding and Templates with the Model-View-ViewModel methodology. Because I’m having a lot of feedback on posts I wrote about how transitions can be done in WPF, I decided to reuse my previous demo application and add transitions when switching from one element to another. Here is the result of the demo application:

Get the Flash Player to see this content.

I didn’t wanted to implement all the transitions, instead I decided to use the famous FluidKit library and to wrap its transition control into a reusable and “MVVM compliant” control. I thank Pavan Podila for giving me feedback while designing this control.

Basically, based on Pavan suggestions I created an INavigationAware interface and subclass transitions I wanted to reuse from FluidKit. The INavigationAware interface allows me to specify that the transition supports going forward and going backward (regarding the previous and current selection of the user in the menu).

The control itself (that I call a NavigationPresenter) is very simple, I just use 2 ContentPresenter that I switch when the Content property changes using the TransitionPresenter control from the FluidKit library. The NavigationPresenter works with 3 dependency properties:

  • GoForward (bool): to specifiy the way of the transition
  • Transition: to specify the transition to use
  • Content: to specify the content of the control

Here is the XAML for using the NavigationPresenter

<!-- The ContentProperty is not bound directly to the SelectedItem of the ListBox because the
     GoForward property must be updated BEFORE the content changes. The CurrentContent property
     is defined in the ViewModel class and updated everytime the selection of the ListBox changes,
     after setting up the GoForward value. -->
    Content="{Binding CurrentContent}"
    Transition="{Binding ElementName=transitionComboBox, Path=SelectedItem.Tag}"
    GoForward="{Binding DataContext.GoForward, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type AnimatedContentPresenter:MainDialog}}}">            

The sample application comes with 3 animations but more can be used from the FluidKit library. It’s also possible to create your own transition (inherit from Transition base class). You can download the sample application here. Hope you’ll like it !

TransitionPresenter control from FluidKit

By looking at Worpress statistics for my blog, I realized that many people were coming here by searching keywords like “animation”, “transition”, etc. A couple of month ago, I wrote an article about a control that I created: the ContentSlider control. The article described a control that could be used to create an animation when switching from one page to another, but it was very basic.

If you’re looking for a more complete solution, I recommend you to take a look at the FluidKit library created by Paven Podila. The FluidKit library contains very powerful control, the most known is probably the ElementFlow control that is similar to Apple’s famous CoverFlow functionality:

FluidKit also contains a TransitionPresenter control that is an extended and more powerful version of my ContentSlider control. The TransitionPresenter control comes with 4 transitions that you can easily use in your application (Cube, Flip, Slide, Genie):

Pavan really did a great job with the FluidKit library. Go ahead a grab the source to play with it and learn very cool stuff about WPF !

Introducing the ContentSlider control

In my very first article, I wrote an article about an implementation of a solution allowing to use transition (using a sliding effect) between views in a WPF application.

As a reminder, here when I talk about “views” I mean a screen of the application. One of this screen could be used as a login screen, the other one to setup parameters, etc.

In this article, I introduce a CustomControl that I build in order to re-use the implementation I described in an easy way. Basically, using this control, you can write something like:

    <!-- here is the content -->

All the specific stuff related to the transition (the animation, the use of a VisualBrush…) is handled INSIDE the control so that it is completely transparent to use.

From C# code point of view, you’ll need to use 3 functions:

  • PrepareSlide()
  • SlideToLeft()
  • SlideToRight()

The first one (PrepareSlide) must be called right before changing the content of the view. It will create a “snapshot” of the view so that it will become possible to animate it.

The next two one should be called to slide the content to the left (or to the right).

I hope you’ll enjoy it. Here is a solution containing the control with example.