MasterDetail and NavigationPage deeplinking in Prism Forms - xamarin.forms

I am testing the deeplinking feature of the Prism Forms framework. I currently have a situation where I have a MasterDetailPage with a menu as Master. When I click the menu items, the Details should change to specific pages with a clean NavigationPage as container.
When I check the Sandbox example for Prism Forms, it shows an example for MasterDetail navigation, but not including navigation pages.
So I have this (absolute) deeplink structure at startup: /MasterDetailPage/NavigationPage/MyFirstPage
Then I want the second menu item to link to a fresh NavigationPage:
/MasterDetailPage/NavigationPage/MySecondPage
My current workaround is to do absolute deeplinking, but I was wondering if there is a better way? The Prism PageNavigationService checks to see if the segment type is the same as the current detail type. But since these are both NavigationPages, it tries to add the new page in the already existing NavigationPage. At that moment it also kills the menu-icon (at least on iOS).

Actually, the Sandbox app does use NavigationPages in the MasterDetail: https://github.com/PrismLibrary/Prism/blob/master/Sandbox/Xamarin/HelloWorld/HelloWorld/HelloWorld/Views/MyMasterDetail.xaml
Prism reuses the detail page for performance reasons, but it doesn't work like you think it does. While it does add the new page to the NavigationPage's NavigationStack, it also removes the previous page from the stack. This keeps the NavigationStack in the proper state.
The icon behavior you are seeing is because of a confirmed bug in Xamarin.Forms. You can follow the issue here: https://bugzilla.xamarin.com/show_bug.cgi?id=41038
As soon as Xamarin fixes this bug, I will publish the fix to Nuget. In the mean time, the only way to get around this is to fork the Prism code base and remove the Page type check.

Related

How do I change the content shown in the master section of a master detail page using Prism

I'm migrating our app from MvvmCross as we need to add Intune support and using MVX is preventing this.
The app is essentially an email reader, so currently we are using a MasterDetail page and loading a folder list into master which on phones becomes the flyout and on tablets this appears in the left of the split view.
When you select a folder from this page we then show a message list - this loads into the detail on phone, but for tablets we use MVX functionality to load this into master, this is also wrapped inside a nav page so you can go back to the folder list. Essentially we have a nav stack inside the master section on tablets and also one in the detail section.
I've checked and played around with the Prism samples, but they don't appear to cover this scenario. The documentation recommends only having fixed content in the master section and this is bound to the master detail view model. This is different to what we have currently, essentially we can control where any page ends up depending on idiom.
I would just like confirmation that it is possible for me to be able to load a page into detail or master depending on the device idiom and any examples would be greatly appreciated!
The Master property of the MasterDetailPage is a basic Page object so it does not have a navigation stack available but the property itself does have a getter and a setter so you should be able to set the page manually. We use a master page and as a quick test I was able to set it using:
((MasterDetailPage)Application.Current.MainPage).Master = new SwapMaster();
What might be possible that I didn't try is actually set the Master as a NavigationPage. Then you might be able to push onto the Master's navigation stack. Again, I did not try this ATM.
Update:
So I did play around quickly with setting the Master to a navigation page and then pushing and popping pages on and off the stack. It did work but the behavior was a little squirrelly but it does show it might be possible.
Push on the stack:
((NavigationPage)Master).Navigation.PushAsync(new SwapMasterPage());
Pop the stack:
((NavigationPage)((MasterDetailPage)Application.Current.MainPage).Master).Navigation.PopAsync();
I've answered this myself by taking a look in the source and there is no support in the Prism navigation service to load a page into master. Everything is overridable, but I feel it would result in lots of changes and issues if I try and introduce this concept.
We'll have to discuss internally if changing the UI flow on tablets is acceptable, if not then Prism is a no go and we'll look at alternatives or write our own navigation service to support it.

bypass tab click in tabbed page

My application is using a tabbed page to separate 2 main areas. Using Xamarin.Forms 4.x and Prism.
The first tab basically hosts a set of linear navigated views modelling a workflow. It's been identified that when a user has progressed through the workflow, and accidentally taps on the current tab, the user is popped back to the start of the navigation.
Is there any way to bypass this event?
This only seems to happen on iOS.
I just discovered the answer. Works perfectly.
https://forums.xamarin.com/discussion/144478/ios-stop-tab-re-select-pop-to-navigation-page-root

Prism detecting if page is modal programmatically and go back

I am implementing a feature using "connectivity" from essentials that when the app goes "offline" no wifi etc.. it navigates to a specific page.
It works in most cases however if I set the phone on "Airplane Mode" when I am on a modal page it does not navigate to my page.
In Prism is there a way to detect if the current page "IsModal" and either goback or kill it so that I can navigate to my specific Page?
THanks
You'd have to write some crazy lookup logic to figure it out. Unfortunately the helper for that doesn't currently exist. However the latest Prism 7.2 preview has some enhancements that specifically attempt to eliminate the need to figure out whether you require Modal Navigation and automatically use the proper type of Navigation. I would encourage you to try the preview. If you come up with a scenario where GoBack isn't working correctly please open an issue.

NavigationService won't navigate after going there via absolute Navigation

I am currently working on a Xamarin.Forms application that is targeting UWP, iOS and android.
After implementing a login dialog I am navigating a logged in user to a SomeContentPage, which I now want to be enclosed into a NavigationPage (and perhaps later on inside a MasterDetailPage).
I am trying to reset the navigation stack by using a /-prefix for a absolute navigation route, which will bring the user to the desired page and clear the stack:
await NavigationService.NavigateAsync("/NavigationPage/SomeContentPage");
Following, from this page there is no more relative navigation possible:
var navigationResult = await NavigationService.NavigateAsync("AnotherContentPage")
It seems like that there is everything going well "inside" the navigation system (navigationResult.Success is true) but the app is not navigating to the AnotherContentPage at all.
If I navigate without the /-Prefix, the upcoming navigation calls work as expected:
await NavigationService.NavigateAsync("NavigationPage/SomeContentPage");
I am really concerned and I already investigated very hard on this.
I don't know if I am just not understanding something properly in the Prism.Forms NavigationService concept or if I am trying something impossible here.
I re-read the Prism.Forms documentation, watched several YouTube-tutorials and read many blog posts about navigation in Prism.Forms.
I am near to desparation right now.
I really feel bad asking this and I am really questioning my internet-research-skills at this moment, but it would be great, if someone of you could give me some advice, how to handle this.
Thanks in advance and have a nice day!

UI issue with Prism MasterDetail implementation

I am using github.com/PrismLibrary/Prism/tree/master/Sandbox/Xamarin/HelloWorld to implement MasterDetail using Prism.
I have successfully ran the example and all is fine but the menu is covering phone top notification area. How can I solve this?
Please see the issue here
In Xamarin example https://developer.xamarin.com/samples/xamarin-forms/Navigation/MasterDetailPage/
this issue is not happending.
Do I have to do some addition trick with Prism that is not done in HelloWorld example?
Thanks
Tadas
That is an old sample that does not use Material Design. All the newer Xamarin.Forms templates utilize material design which result in the master showing over the topmost bar. You could also try playing with the MasterBehavior property to control how the master behaves.

Resources