Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 81910

Only the original thread that created a view hierarchy can touch its views - what is the cause?

$
0
0

Hello. The question has been asked in the forum previously but the source of the problem is different for each developer and the limited answers don't help my case.

I use a pattern to display a splash screen in my app that works for a previous app. It goes as follows:
1. In App.Xaml.cs I call MainPage = new NavigationPage(new SplashPage());
2. In SpashPage's OnAppearing method I call App.Current.MainPage = new NavigationPage(new FPMainPage());

Below is the code:

      public App()
        {
            Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("***");

            InitializeComponent();
            MainPage = new NavigationPage(new SplashPage());
        }
...
namespace FP.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class SplashPage : ContentPage
    {
        public SplashPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);
        }

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

            await splashImage.ScaleTo(0.9, 500, Easing.Linear).ConfigureAwait(false);
            await splashImage.ScaleTo(0.6, 200, Easing.Linear).ConfigureAwait(false);
            await splashImage.ScaleTo(0.3, 200, Easing.Linear).ConfigureAwait(false);
            await splashImage.ScaleTo(0.0, 200, Easing.Linear).ConfigureAwait(true);

            App.Current.MainPage = new NavigationPage(new FPMainPage());
        }
    }
}
...
public FPMainPage()
        {
            BindingContext = _viewModel;

            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            try
            {
                base.OnAppearing();
                _viewModel.LoadData();

                _nextSchedule = _viewModel.EarliestSchedule();

                foreach (ItemGroup<string, Game> item in ListViewGames.ItemsSource)
                    if (_nextSchedule == item)
                    {
                        ListViewGames.SelectedItem = item;
                        ListViewGames.ScrollTo(item?.FirstOrDefault(), Xamarin.Forms.ScrollToPosition.Start, true);
                        break;
                    }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

        }

The error occurs at FPMainPage InitializeComponent. What change do I need to make so that it works?

Thank you!


Viewing all articles
Browse latest Browse all 81910

Trending Articles



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