Bug 41854 - [UWP] NavigationPage back button remains when resetting Application.Curent.MainPage to ContentPage
Summary: [UWP] NavigationPage back button remains when resetting Application.Curent.Ma...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Rui Marinho
URL:
Depends on:
Blocks:
 
Reported: 2016-06-15 16:02 UTC by Brian Lagunas
Modified: 2016-07-05 18:46 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Brian Lagunas 2016-06-15 16:02:40 UTC
Using Xamarin.Forms 2.3.38-pre2

In a UWP application, when you have a NavigationPage with a couple of ContentPages in the Navigations stack, the back buttons shows as expected.  The issue is that when you reset the Application.Current.MainPage to a new instance of a ContentPage, the old NavigationPage's back button is still present in the UI.  There should be no back button because I no longer have a NavigationPage set as the MainPage.  Run this code to reproduce the issue:

    public partial class App : Application
    {
        public App()
        {
            MainPage = new MainPage();
        }
    }

    public class MainPage : ContentPage
    {
        public MainPage()
        {
            Title = "MainPage";

            Button btn = new Button() { Text = "Navigate from MainPage", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center };
            btn.Clicked += Btn_Clicked;

            Content = btn;
        }


        private void Btn_Clicked(object sender, System.EventArgs e)
        {
            Navigation.PushModalAsync(new NavigationPage(new ViewA()));
        }
    }

    public class ViewA : ContentPage
    {
        public ViewA()
        {
            Title = "View A";

            Button btn = new Button() { Text = "Navigate from View A", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center };
            btn.Clicked += Btn_Clicked;

            Content = btn;
        }

        private void Btn_Clicked(object sender, System.EventArgs e)
        {
            Navigation.PushAsync(new ViewB());
        }
    }

    public class ViewB : ContentPage
    {
        public ViewB()
        {
            Title = "View B";

            Button btn = new Button() { Text = "Navigate from View B", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center };
            btn.Clicked += Btn_Clicked;

            Content = btn;
        }

        private void Btn_Clicked(object sender, System.EventArgs e)
        {
            Application.Current.MainPage = new MainPage();
        }
    }
Comment 1 Rui Marinho 2016-06-16 16:38:40 UTC
Should be fixed in 2.3.1-pre1
Comment 2 Parmendra Kumar 2016-07-04 18:12:09 UTC
@Rui, I have checked this issue with Xamarin.Forms.2.3.1.111-pre2 and observed that Back button not showing on UWP and its working fine with Android.

Screencast: http://www.screencast.com/t/XmWgsFL3dhOa

Hence reopen this issue.

Please let me know if I have missed anything to verify this issue.

Thanks.
Comment 3 Rui Marinho 2016-07-05 11:40:40 UTC
This is UWP desktop.