MainPage Animated Transitions

AdamPAdamP AUUniversity ✭✭✭✭✭
edited March 2017 in Xamarin.Forms


To provide the ability for the update of the MainPage property to show animation during transition, of the page of it being changed to.

API Changes

There are three ways to approach this and I am not sure which would fit best.

  1. Provide a property in Application.cs to set a pre-existing animation. e.g.

    Application.Current.MainPageAnimation = Animation.SlideInFromLeft

  2. Provide a method to do only do the animated transition during a set. e.g.

    Application.Current.SetMainPage(newMainPage, Animation.SlideInFromLeft);

    These first 2 assume that Xamarin Forms will control the transition and not provide any customization. The next point, is expanding it to be able to add custom animations.

  3. Give control of animations to the platform. In the platform, define the animation. This is an Android example.

    Xamarin.Forms.Platform.Android.Platform.RegisterAnimation("AnimationName", Application.Current.AnimationUtils.LoadAnimation(_context, global::Android.Resource.Animation.SlideInLeft);

    Then set the animation via the string, based on either choice of the first 2 points.

Intended Use Case

A common pattern to separate the login screens with the main application is to change the MainPage property in Application. Some MVVM frameworks also rely on this, such as FreshMVVM and Exrin. This would allow the ability to provide an animation when transitioning between different Pages at the root level.


Open · Last Updated


  • AdamPAdamP AUUniversity ✭✭✭✭✭
    edited March 2017

    I have also done a very rough test to see if its possible, which it is via the below code.

    Note: This isn't how I would implement it, I just wanted to show that it could be done, and where the animations need to be set.


    In FormsAppDelegate.cs change this function

    void UpdateMainPage()
       if (_application.MainPage == null)
        var platformRenderer = (PlatformRenderer)_window.RootViewController;
        if (platformRenderer != null)
        if (_window.RootViewController == null)
            _window.RootViewController = _application.MainPage.CreateViewController();
            UIView.Transition(_window.RootViewController.View, 1, UIViewAnimationOptions.TransitionFlipFromBottom, () => { _window.RootViewController = _application.MainPage.CreateViewController(); }, () => { });


    Android proves the hardest because I can only seem to transition in, once the previous page is removed. In Platform.cs I replace the following function:

    void AddChild(Page page, bool layout = false)
       if (Android.Platform.GetRenderer(page) != null)
        Android.Platform.SetPageContext(page, _context);
        IVisualElementRenderer renderView = Android.Platform.CreateRenderer(page);
        Android.Platform.SetRenderer(page, renderView);
        if (layout)
            LayoutRootPage((FormsAppCompatActivity)_context, page, _renderer.Width, _renderer.Height);
        renderView.ViewGroup.StartAnimation(global::Android.Views.Animations.AnimationUtils.LoadAnimation(_context, global::Android.Resource.Animation.SlideInLeft));


    In UWP we add in this to the SetCurrent method in Platform.cs, just before the Children.Add line.

    if (_container.ChildrenTransitions == null)
        _container.ChildrenTransitions = new TransitionCollection();
        _container.ChildrenTransitions.Add(new EntranceThemeTransition());
  • DavidGerding.4136DavidGerding.4136 USMember ✭✭

    I'm interested in this approach, too. Let me know if you made any progress on your experiments or found related code.

  • ramonesteban78ramonesteban78 ESUniversity ✭✭

    Hi @AdamP, 100% agree with the API propousal change. Is there a way to achieve this with Custom Renderers or perhaps using a Service with an implementation for each platform?

    Thanks in advance!

  • MikilllMikilll Member ✭✭✭

    Hey, I am still interested in this API change. Has something changed in this problem till now?

  • DanielMezaDanielMeza COMember ✭✭

    Any update on this?

  • PaulBrennerPaulBrenner USUniversity ✭✭

    If you mean something like this I would add a comment to it, they seem to respond more to github than the forums. But they have 900+ bugs to work on, so I have a feeling this is very low priority.

Sign In or Register to comment.