Xamarin.Forms
Xamarin.Forms copied to clipboard
Using query parameter causes page to be outside of navigation stack [Bug]
Description
I'm creating my flyout items in code behind of AppShell.xaml.cs. I registered a route. When I call my page using a route with query parameter a back button is displayed. When I do the same without the query parameter the hamburger icon is displayed.
Steps to Reproduce
-
Create a soulution using the template offered
-
Delete xaml Flyout declared in AppShell.xaml
-
Register route to a page
Routing.RegisterRoute(nameof(Container), typeof(Container));
-
Add a new item like this:
Items.Add(new FlyoutItem{ FlyoutDisplayOptions = FlyoutDisplayOptions.AsSingleItem, Title = "StaticFlyoutTitle", Route = "AccessContainer", Items = { new Tab { Title = "Access", Route = "AASSWE2", Items = { new ShellContent { Title = "ShellContentTitle", Route = $"Container?bookingcodeproperty=AASSWE2", ContentTemplate = new DataTemplate(typeof(Container)), } } } } });
-
Add another item like this:
Items.Add(new FlyoutItem { FlyoutDisplayOptions = FlyoutDisplayOptions.AsSingleItem, Title = "StaticFlyoutTitle", Route = "AccessContainer", Items = { new Tab { Title = "Access", Route = "AASSWE2", Items = { new ShellContent { Title = "ShellContentTitle", Route = "Container", ContentTemplate = new DataTemplate(typeof(Container)), } } } } });
-
Observe the different behaviour
Expected Behavior
Both FlyoutItems should behave the same
Actual Behavior
The FlyoutItem calling the page using a query paramter seems to be outside of the navigation stack. A Backbutton is displayed instead of the Hamburger.
Basic Information
- Version with issue: vs 16.7.2, Xamarin 16.7.000.440
Workaround
Set NavBarIsVisilble to false and add a Hamburger-button with command: Shell.Current.FlyoutIsPresented = true; Dirty hack!
@GO74 what should happen here is that the app crashes with a "duplicate route" detected exception
You've registered a route
Routing.RegisterRoute(nameof(Container), typeof(Container));
And a route on the ShellContent
Route = "Container",
These are two different routes
When you click on the second FlyoutItem Shell just sends the route "Container" into shell which then uses the page you've registered here
Routing.RegisterRoute(nameof(Container), typeof(Container));
What are you trying to achieve here?
@PureWeen what I'm trying to archive is to call my view using a parameter like that:
Route = $"Container?bookingcodeproperty=AASSWE2"
It should behave exactly like calling the view without the paramter, but it doesn't.
If I do it without registering a route I get this exception:
If I do register a route, I don't get an exception, but a Back-button is shown in the container-view instead of the Hamburger-button. Pressing the Back-button is opening the very same view. This doesn't make sense imho and is the reason why I think it's a bug. If I misunderstood something and made a mistake I apologise and would kindly ask for advise on how to make a call like that properly without the currently observed behavior, instead the view should have the Hamburger-button and there shouldn't be a copy of the view in the stack, just as if I would call the view without parameter.
You can observe the behaviour yourself with this: mroomote_navTest.zip
@GO74 can you tell me what your expectation is here?
What do you want the UI to look? What tabs do you want on the screen?
What do you mean by this statement?
When I call my page using a route with query parameter a back button is displayed.
Sure, I expect the very same look and behaviour as if I call the view without parameter. I also explained the issue here: https://forums.xamarin.com/discussion/comment/421688#Comment_421688
@GO74 the problem is that I don't understand what your end design goal here is
If you
- remove the register route
- just register a ShellContent with Route "Content"
- then navigate to that route with "\Content?Query=1"
then that won't push anything onto the navigation stack that will just pass the Query value into your BindingContext
https://devblogs.microsoft.com/xamarin/xamarin-forms-shell-query-parameters/
You don't add the parameters to the route
@PureWeen Okay, got it. So this is the navigation experience I need to provide:
And this is how it is currently behaving:
The workaround/dirty hack I came up with is to set NavBarIsVisible = false and create my own 'NavBar' with a button which triggers the flyoutmenu.
@PureWeen I am trying to achieve something similar to what @GO74 is trying to achieve. When setting up the route if I add query parameters then the app crashes:
The exception that is thrown is: System.ArgumentException: unable to figure out route for: //animals/domestic/cats?param1=50
The reason why I am trying to do this is to have the query parameter to have one value when navigating from the tabbar and when navigating from some other page to have a different value.