I do not get the "back" arrow in Master Detail Page - xamarin.forms

With the standard (template) implementation of Master Detail Page, I do not get a back button when I call the side menu.
Standard implementation looks like this:
<NavigationPage>
<x:Arguments>
<local:DetailPage1/>
</x:Arguments>
</NavigationPage>
But when I implement navigation in this way:
MainPage = new NavigationPage(new MainPage());
i get the button back
Why does this happen and why I do not get a button with the standard (template) implementation? Thanks
screenshot with a running button at the bottom
enter image description here

First of all - the menu (master page) should not have a back button.
From the official documentation:
A MasterDetailPage is designed to be a root page, and using it as a
child page in other page types could result in unexpected and
inconsistent behavior. In addition, it's recommended that the master
page of a MasterDetailPage should always be a ContentPage instance,
and that the detail page should only be populated with TabbedPage,
NavigationPage, and ContentPage instances. This will help to ensure a
consistent user experience across all platforms.
If your MasterDetailPage is not a root page and it is wrapped by a NavigationPage you may see the back arrow.
That should answer your question. Additional details and restrictions are listed in the same official doc.

Related

HelloWorld sample code not working on Android: Back button not visible

I got the sample app from
https://github.com/PrismLibrary/Prism/tree/master/Sandbox/Xamarin/HelloWorld
I tested it on Android 6:
Run the app from sample code (no modifications), it shows MainPage
Tap on ViewA from the menu, it navigates to ViewA, but there is no back button in the app bar.
Hitting device back button works, it navigates back to MainPage.
The behavior I am expecting is to see the back button in the bar too.
UPDATE
I'm debugging Prism, and I can see clearly that Prism's PageNavigationService navigates to ViewA by just calling currentPage.Navigation.PushAsync(page, animated).
I can see that the Xamarin Forms's NavigationImpl has the NavigationStack with two pages, MainPage and ViewA. So the MainPage is still there in the navigation stack, but for some reason the back button is not visible.
ANSWER!
#lowleetak discovered that there is a call somewhere in the sample which hides the back button!
The app start in MasterDetail page. Where the MasterPage is the Menu and DetailPage is the MyNavigationPage/MainPage initially.
When you click ViewA from menu, it is changing the DetailPage from MainPage to MyNavigationPage/ViewA. It is the root/initial page in the navigation stack of the DetailPage. So, there is no Back button showing.

Xamarin.Forms Master/Detail back stack with Prism

I'm using Xamarin.Forms with Prism and a Master/Detail to create a "hamburger" menu. When the app runs, I navigate to NavigationService.NavigateAsync("MyMasterDetailPage/MyNavigationPage/MainPage");
I have items in the Master flyout menu for navigating to other pages. So I tap one and navigate to MyNavigationPage/SyncPage. At this point, if I hit the back button on Android, the app closes. Instead, I'd like to navigate back to the MainPage. I tried to hook into OnNavigatedFrom of the SyncPage to force navigation back to MainPage but the app is already closing by the time that event fires.
Implement the INavigationPageOptions interface on MyNavigationPage and set ClearNavigationStackOnNavigation = false
I implemented a solution similar to what Brian suggested but had to add a check to return true if it's the first time through in order to work correctly.

Xamarin.Forms Back Stack of NavigationPage inside Details view of MasterDetail using PRISM

I'm using Xamarin.Forms with PRISM. My app start with navigating to MyMasterDetailPage/MyNavigationPage/MainPage. From the master page, I want to navigate to page2 and have a back arrow instead of the hamburger icon. Pressing that takes you back to MainPage and the hamburger icon is back. I have tried navigating to MyNavigationPage/page2 andMyMasterDetailPage/MyNavigationPage/page2` but it seems to be clearing the back stack. There may be other pages that need the behavior that I'm currently seeing, so being able to configure the behavior would be ideal (not always one way or the other).
You need to implement the INavigationPageOptions interface on your MyNavigationPage and set the ClearNavigationStackOnNavigation property to false.

Xamarin Forms: Toolbar not showing in Jellybean 4.3

I am using Xamarin Forms, added the below code for Toolbar, but it not showing on the right top (with 3 dots) and but I could see Menu when I use Menu hardware button on device.
Device running Android Jelly bean 4.3.
<ToolbarItem Text="QUICK LINKS" Activated="OnToolBarClick" Order="Secondary" Priority="0" />
Any suggestion?
Make sure that when you create the instance of the page containing the toolbar, you use the NavigationPage class to wrap it, otherwise the toolbar will not be displayed.
For example, assume UpdateScoresPage is the page with the toolbar in, and we're calling this from the parent page. If you omit new NavigationPage(page) the toolbar will not show.
UpdateScoresPage page = new UpdateScoresPage(Model, model);
await Navigation.PushModalAsync(new NavigationPage(page));

How to navigate to a new Screen when using SideBarController in Xamarin.iOS

I have an application with a lot of screens, let say HomePage, Section Screen and Detail Page, Category Screen.
I use a NavigationController to Navigate from HomePage to Section Screen.
In the SectionScreen I have used a SideBarController component (https://components.xamarin.com/view/sidebarnavigation) to implement a navigation drawer or a flyout menu.
The problem is how to navigate from Section Screen to Detail Page or to Category Screen. I need to make this kind of navigation from MenuController or ContentController.
I don't want to just change the contentView. I want to push another UIViewController.
I have used the usual one:
this.NavigationController.PushViewController( new UIViewControllerExample(), true);
but there are some problems:
In the details page I can't access the NavigationBar
When I press back, the app crashes with an error:
Cant add self to subview
This is how to it should look like.
This is the problem. The first image display what happen when i use the above code,
Any idea how to solve this.
as you can find in that page of component you should use SidebarController as your navigationcontroller
SidebarController.ChangeContentView(new OtherContentController());

Resources