简体   繁体   English

Xamarin.forms android Prism 处理硬件后退按钮

[英]Xamarin.forms android Prism handle hardware back button

I am having issue while handling back button on android device.我在处理 Android 设备上的后退按钮时遇到问题。 I want to handle navigation stack while user press hardware back button how I can achieve this?我想在用户按下硬件后退按钮时处理导航堆栈,我该如何实现?

You can override the OnBackButtonPressed() function您可以重写OnBackButtonPressed()函数

protected override bool OnBackButtonPressed (){
    //Handle your navigation here
}

Details from the official docs官方文档中的详细信息

Note : this will only work for Android, but that seems to be the only platform you are asking for.注意:这仅适用于 Android,但这似乎是您要求的唯一平台。 If you require a cross-platform solution, see this question.如果您需要跨平台解决方案,请参阅问题。

I don't know it's a good practice, but it worked to me.我不知道这是一个好习惯,但它对我有用。

protected override bool OnBackButtonPressed()
{
    var vm = (SignInViewModel)BindingContext;

    vm.GoBackCommand.Execute();

    return base.OnBackButtonPressed();
}

At ViewModel you can handle what you want to perform.在 ViewModel 中,您可以处理您想要执行的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM