The back button can be software-based (in-app button) or hardware-based (OS back key). In MAUI Shell mode, these two types of back buttons are handled differently.
-
Handling software button
In the page, bind an event handler to the back button. In this case, the hardware back button will still navigate to the previous page.1 2 3
<Shell.BackButtonBehavior> <BackButtonBehavior Command="{Binding ButtonCommand}"/> </Shell.BackButtonBehavior>
-
Handling hardware button
The hardware back button requires overriding theOnBackButtonPressed
method in the page’s.cs
file.1 2 3 4 5
protected override bool OnBackButtonPressed() { // your code return base.OnBackButtonPressed(); }