Reputation: 5968
I need to handle the back button action in .Net Maui.
I'm not talking about the device backbutton. But the navigation page back button :
I tried this code but it works only on the device back button and not navigation page back button.
protected override bool OnBackButtonPressed()
{
// Do something here
return base.OnBackButtonPressed();
}
How can I handle that?
Upvotes: 7
Views: 16218
Reputation: 839
Use the below code to handle the back button in MAUI app and the same code will work for WebView as well.
protected override bool OnBackButtonPressed()
{
if (WebView.CanGoBack)
{
WebView.GoBack();
return true;
}
else
{
base.OnBackButtonPressed();
return false;
}
}
Upvotes: 9
Reputation: 4586
You can set the Shell Navigation back button by using the back button behavior.
Here is the information about Back button behavior.
Upvotes: 4
Reputation: 414
I think that this will help: "Back button appearance and behavior can be redefined by setting the BackButtonBehavior attached property to a BackButtonBehavior object", according to MAUI documentation.
Using "Command" property you can define the actions to executed when back-button is pressed.
Upvotes: 7