6
votes

I have a simple Xamarin Forms app using UWP. I am pushing to a new view:

await Navigation.PushAsync(new NavigationPage(new MyDetailView()));

When that view loads, there is no back button to return up the stack. What is the recommended approach? Note in iOS the back button is present.

1
Can't you create your own back button and then when it's pressed invoke the back logic?Anthony Russell
I'm trying to keep things within the Xamarin Forms paradigm. It surprises me this isn't baked in some way.aherrick
It's not baked into the desktop UWP apps. You need to create your own back button there too.Anthony Russell
Looks like they are doing it here: github.com/xamarinhq/app-acquaint not sure how exactlyaherrick
As of 2017-08-29 it is not including the back button in a default app created from the VS2017 template.Andy Dent

1 Answers

10
votes

The back button on Desktop can be shown using the following code snippet:

SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
   AppViewBackButtonVisibility.Visible;

This will display the back button in the app's title bar. You might want to update this status on each navigation, so that the button is not displayed when it is not needed (when the navigation stack is empty).

But I guess this should happen automatically, as this is the behavior that is already in the Xamarin.Forms - see the NavigationPageRenderer source line 463.

I think the problem might be the fact, that you are pusing a the new view wrapped inside a new NavigationPage which steals the navigation stack and has it empty. I suppose this should work as you expect and solve your problem (pushing just the new view in the existing NavigationPage):

Navigation.PushAsync( new MyDetailView() );