Moving to next page after animation page

scheradyscherady brian scheradyATMember

In the first page I have an introduction that consists of showing a succession of images. At the end of the animation I need to move to the next page.
How can I do it?

Best Answer

  • scheradyscherady brian scherady ATMember
    Accepted Answer

    Solved !

    I simply added

    Application.Current.MainPage = new NextPage();

    in EndIntro()

Answers

  • JimBennettJimBennett Jim Bennett GBInsider, University, Developer Group Leader ✭✭✭✭

    Need more info - Forms, native, iOS, Android, Mac, UWP...

  • scheradyscherady brian scherady ATMember

    Forms.
    My problem is at the end of the animation, I need to move automatically to another page.

  • JimBennettJimBennett Jim Bennett GBInsider, University, Developer Group Leader ✭✭✭✭

    What exactly is your problem - do you need to know how to show another page or detect when animation has finished.

    Are you using any frameworks (Prism, FreshMvvm)?
    Any code to show?

    We're not mind readers - the more information you can provide the more likely someone will be able to help.

  • mikeacostamikeacosta Michael Acosta USUniversity

    Not sure if this is what you're after, but I have an initial "splash" ContentPage with code like this in the OnAppearing() override.

    async protected override void OnAppearing()
    {
        // animation code here - logo grows & fades in
    
        // then a brief delay before going to next page
        await Task.Delay(TimeSpan.FromSeconds(2));
        App.Current.MainPage = new NextPage();
    }
    
  • DavidDancyDavidDancy David Dancy AUMember ✭✭✭✭

    So are you saying

    a) the animation doesn't finish before App.Current.MainPage gets assigned
    b) the MainPage assignment doesn't work?

  • scheradyscherady brian scherady ATMember

    I have a page "Introduction" in which a timer launches n pictures (it works fine).
    In app.cs I set MainPage = new Introduction()
    At the end of animation what (and where) should I do to move to NextPage() ?

    @mikeacosta
    where do I put the OnAppearing() override? In Introduction I do not have access to App.Curent.MainPage

    @DavidDancy
    a) the animation finishes normally (or is skipped with a button, also normally)
    b) where to assign the MainPage ?

  • mikeacostamikeacosta Michael Acosta USUniversity
    edited March 21

    Your Introduction page might look like this:

        public partial class Introduction : ContentPage
        {
            public Introduction()
            {
                InitializeComponent();
            }
    
            async protected override void OnAppearing()
            {
                // animation code here
    
                await Task.Delay(TimeSpan.FromSeconds(2));
                Application.Current.MainPage = new NextPage();
            }
        }
    
    

    Either of these should work to access MainPage:

    Application.Current.MainPage
    App.Current.MainPage

  • scheradyscherady brian scherady ATMember

    `My introduction page looks like this:

    public class Introduction : ContentPage
    {
    AbsoluteLayout introLayout = new AbsoluteLayout {};

            .
            . //define variables
            .
    
        public Introduction()
        {
            .
            . //define images
            .
    
                    int ms = 3000;
    
            Device.StartTimer(TimeSpan.FromMilliseconds(ms), imageChange);
    
            //Add skip intro button
            skipIntroButton();
    
    
            // Set page content
            Content = introLayout;
    
        }
    
        private bool imageChange()
        {
            DoNotStopTimer = true;
    
            if ((imageName[imageIndex] == null) | (imageIndex == ConstImages))
            {
                DoNotStopTimer = false;
                EndIntro();
            }
            else
            {
                .
                . //change images
                .
            }
    
            return DoNotStopTimer;
        }
    
        private void SkipIntro(object sender, EventArgs e)
        {
            imageIndex = ConstImages;
            DoNotStopTimer = false;
            EndIntro();
        }
    
        private void EndIntro()
        {
    
            introLayout.Children.Remove(currentImage);
            introLayout.Children.Remove(skipIntroBtn);
    
        }`
    

    In any case the animation ends via EndIntro()

  • scheradyscherady brian scherady ATMember
    Accepted Answer

    Solved !

    I simply added

    Application.Current.MainPage = new NextPage();

    in EndIntro()

Sign In or Register to comment.