Xamarin.forms: [Enhancement] Enable BackButtonBehavior for non Shell Apps

Created on 25 Jul 2019  ·  5Comments  ·  Source: xamarin/Xamarin.Forms

Summary

Create an Attached Property you can use on NavigationBars/TabBars/ContentPages/MDP that works like Shell for controlling the behavior of the back button. BackButtonBehavior has a lot more features than the current back button implementation on non Shell.

Original Summary

By adding this property, developers gain more control over the NavigationBar design and it will be a good addition to the TitleView.

API Changes

  • NavigationPage.BackButtonBehavior //Attached Property
  • MasterDetailsPAge.BackButtonBehavior //Attached Property

API Changes from Original Ticket

Similar to how NavigationPage already has the NavigationPage.HasBackButton property, we should add:

NavigationPage.HasFlyoutButton
NavigationPage.SetHasFlyoutButton()

Should be implemented on all platforms. Should make sure this works with the new Shell as well.

Intended Use Case

There are a lot of use cases for this one, but first that comes to mind is when creating an edit form in an application; The user enters edit mode and developer want to restrict navigation and replace all the content in the NavigationBar with "Cancel" and "Save"-buttons.

backbutton high impact proposal-open enhancement ➕

Most helpful comment

note that this would help Prism as well. We'd love to see some priority put on this.

All 5 comments

@TobiasKullblikk I updated the ticket a little bit. Let me know your thoughts.

Can you elaborate on this?

Should be implemented on all platforms. Should make sure this works with the new Shell as well.

NavigationPages aren't really used with Shell

@PureWeen Looks great. Was not aware of BackButtonBehaviour.

Can you elaborate on this?

Sorry for the confusion. I really like the idea of Shell, and wanted to make sure this feature would work with it too. I just haven't had the time to dive into it yet.

Let me know if I can contribute on implementing this one (if accepted) 👍

note that this would help Prism as well. We'd love to see some priority put on this.

@samhouts , how's the consideration going on? Would really like to see this enhancement gets implemented

The API for BackButtonBehavior should get reworked with this

API ideas for this
Everything gets broken out to attached properties

As this is implemented code is generalized to NavigationPageRenderer/MasterDetailsPage on respective platforms

NavigationPage can acquire all the backbutton attached properties as well just replace the word Shell with NavigationPage

MasterDetailsPage can acquire all the flyout properties

```C#

public enum FlyoutIconDisplayOptions
{
FirstPageOnly,
Visible,
Hidden,
}

public enum BackButtonDisplayOptions
{
AfterFirstPageOnly,
Visible,
Hidden,
}

Shell.FlyoutDisplay //Attached Property
Shell.BackButtonDisplay //Attached Property

Shell.BackButtonCommand
Shell.BackButtonCommandParameter
Shell.BackButtonIsEnabled
Shell.BackButtonText
Shell.BackButtonIcon

Shell.FlyoutCommand
Shell.FlyoutCommandParameter
Shell.FlyoutIsEnabled
Shell.FlyoutText
Shell.FlyoutIcon
```

Was this page helpful?
0 / 5 - 0 ratings