innomotion media
innomotion media

Reputation: 922

Xamarin.Forms: Navigating Away from Master Detail Page causes every page afterwards to have two backbuttons in header

I am navigating from a master detail page (which has a side menu) to a normal page that has one back button in the header but nothing else like so:

        btn_anzeigeerstellen_pickcate.Clicked += delegate
        {
            Navigation.PushAsync(new Screen_SwipeView());
        };

I used the empty pages before, and they always had one back button. But now, since I am moving away from the master detail page, the result is this:enter image description here

While the lower backbutton just navigates back, the upper back button navigates to the very beginning of the app again (which is pointless) So the upper back button needs to be removed.

Also, I noticed that by swiping from left screen end to right, it will bring up the menu as from the master detail page, which is not bad, but it shows that the app still "thinks" it is inside the master detail page.

How can I alter that behavior?

Thank you!

Master Detail Page:

public partial class Screen_MainMenu : MasterDetailPage
    {
        public Screen_MainMenu()
        {
            InitializeComponent();
            //MasterPage.ListView.ItemSelected += ListView_ItemSelected;
        }

        private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var item = e.SelectedItem as Screen_MainMenuMasterMenuItem;
            if (item == null)
                return;

            var page = (Page)Activator.CreateInstance(item.TargetType);
            page.Title = item.Title;

            Detail = new NavigationPage(page);
            IsPresented = false;

            MasterPage.ListView.SelectedItem = null;
        }
    }


 public partial class Screen_MainMenuMaster : ContentPage
    {
        public ListView ListView;

        public Screen_MainMenuMaster()
        {
            InitializeComponent();

            BindingContext = new Screen_MainMenuMasterViewModel();
            ListView = MenuItemsListView;
        }

        class Screen_MainMenuMasterViewModel : INotifyPropertyChanged
        {
            public ObservableCollection<Screen_MainMenuMasterMenuItem> MenuItems { get; set; }

            public Screen_MainMenuMasterViewModel()
            {
                MenuItems = new ObservableCollection<Screen_MainMenuMasterMenuItem>(new[]
                {
                    new Screen_MainMenuMasterMenuItem { Id = 0, Title = "Mein Profil" },
                    new Screen_MainMenuMasterMenuItem { Id = 1, Title = "Meine Anzeigen" },
                    new Screen_MainMenuMasterMenuItem { Id = 2, Title = "Merkliste" },
                    new Screen_MainMenuMasterMenuItem { Id = 3, Title = "Website" },
                    new Screen_MainMenuMasterMenuItem { Id = 4, Title = "Kontakt" },
                    new Screen_MainMenuMasterMenuItem { Id = 1, Title = "Hilfe" },
                    new Screen_MainMenuMasterMenuItem { Id = 2, Title = "Einstellungen" },
                    new Screen_MainMenuMasterMenuItem { Id = 3, Title = "Missbrauch melden" },
                    new Screen_MainMenuMasterMenuItem { Id = 4, Title = "Log Out" },

                });
            }

            #region INotifyPropertyChanged Implementation
            public event PropertyChangedEventHandler PropertyChanged;
            void OnPropertyChanged([CallerMemberName] string propertyName = "")
            {
                if (PropertyChanged == null)
                    return;

                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
            #endregion
        }

Upvotes: 0

Views: 148

Answers (1)

FreakyAli
FreakyAli

Reputation: 16519

Well from the code that I can see and the code that I assume you have done I think that you are adding the MasterDetailPage itself into NavigationPage, in turn, causing the double nav bars when the detail page is in a navigation page.

Your master-detail page navigation should look something like this:

App.Xaml.cs

MainPage= new Screen_MainMenu();

Where i assume you have something like:

MainPage= new NavigationPage(new Screen_MainMenu());

Goodluck

Feel free to get back if you have questions.

Upvotes: 1

Related Questions