Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

ScrollToAsync doesn't run when I first start the app

$
0
0

Hi everyone!

So what I am trying to do here is to open the app in the exact same point that I left it last time.
My app consists in just a CarouselPage with several ContentPages, so I need to remember not only the current content page but also the position on the scrollview.

I am already able to open it in the right contentpage, but my issue is that if I close the app, every time I run it again, it doesn't scroll to the right position.
Instead, it opens on the top, and if I, for example, swipe forward to the next contentpage and then backwards (so the OnAppearing() executes again), then it scrolls to the expected position.

Is there any reason why the ScrollToAsync is not executed when the app is opened for the first time?

Thank you very much!

    public partial class I : ContentPage
    {
        public I()
        {
            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();

            //Saves current page
            int CurrentChapter = MainCarouselPage.Capitulos.IndexOf(this);
            Preferences.Set("CurrentChapter", CurrentChapter);

            //Scrolls to las position
            int PosY = Preferences.Get("PositionY", 0);
            scrollView.ScrollToAsync(0, PosY , false);
        }

        private void ScrollView_Scrolled(object sender, ScrolledEventArgs e)
        {
            int PositionY = Convert.ToInt32(this.scrollView.ScrollY);
            Console.WriteLine("Position Y: " + PositionY);
            Preferences.Set("PositionY", PositionY);
        }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>