Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms - UWP Back Button?

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.

like image 397
aherrick Avatar asked Jul 14 '16 16:07

aherrick


1 Answers

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() );
like image 78
Martin Zikmund Avatar answered Nov 02 '22 23:11

Martin Zikmund