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

Can't open modal on new main page

$
0
0

This code fully demonstrates what looks like a bug. Sequence is...

1) App opens
2) Default main page created.
3) Login box popped up.
4) Login box closed. (Click on page to simulate)
5) New main page created.
6) Login box popped up.(Click on page to simulate)
7) Exception.

    using System;
    using System.Threading.Tasks;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;

    [assembly: XamlCompilation(XamlCompilationOptions.Compile)]
    namespace test333
    {
        public class Main1 : ContentPage
        {
            public Main1()
            {
                var btn = new Button();

                btn.Clicked += (sender, e) =>
                {
                    MessagingCenter.Send<object>(this, "LoginLogout");
                    Navigation.PopModalAsync();
                };
                Content = btn;
            }
        }

        public partial class App : Application
        {
            public App()
            {
                InitializeComponent();

                MainPage = new Main1 { BackgroundColor = Color.Red };

                MessagingCenter.Subscribe<object>(this, "LoginLogout", s =>
                    Device.BeginInvokeOnMainThread(async () => await HandleLogOut()));

                HandleLogOut();
            }

            bool login = true;

            async Task HandleLogOut()
            {
                if (login)
                {
                    await MainPage.Navigation.PushModalAsync(new Main1 { BackgroundColor = Color.Orange });
                }
                else
                {
                    MainPage = new Main1 { BackgroundColor = Color.Green };
                }

                login = !login;
            }
        }
    }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



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