OnBackButtonPressed事件未触发

huangapple go评论70阅读模式
英文:

OnBackButtonPressed-Event not reached

问题

在我的.NET MAUI应用程序中,我通过以下方式导航到我的ContentPages之一:

await Shell.Current.GoToAsync(nameof(ManagePeopleItem), true);

该页面在AppShell.xaml.cs中注册:

Routing.RegisterRoute(nameof(ManagePeopleItem), typeof(ManagePeopleItem));

所以,当我显示这个页面时,我可以看到导航栏中的返回按钮"<-"。但当我单击此按钮并重写"OnBackButtonPressed()"时,此代码从未被触发。我还尝试在AppShell.xaml.cs中重写它,但在那里也没有触发。

我做错了什么?

英文:

In my .NET MAUI App, I navigate to one of my ContentPages via:

await Shell.Current.GoToAsync(nameof(ManagePeopleItem), true);

The page is registered in AppShell.xaml.cs via:

Routing.RegisterRoute(nameof(ManagePeopleItem), typeof(ManagePeopleItem));

So, when I display this Page, I can see the Back Button "<-" in my Navigation Bar. But when I click this Button and override "OnBackButtonPressed()" this Code is never reached. I also tried to override it in AppShell.xaml.cs, but it is also not fired there.

What am I doing wrong?

答案1

得分: 0

我测试了你提供的代码。结果显示发生了与你相同的情况。

我搜索了相关的案例。最终我找到了这个:On Screen Back Button Does Not Fire OnBackButtonPressed in Android 在 GitHub 上。当你在 Windows 上运行而不是 Android 时,OnBackButtonPressed 事件可以被触发。但对于 Android,它无法。你可以关注这个问题。

英文:

I tested the code you provided. And it shows the same situation happened to you.

I searched relevant cases about it. Finally I found this: On Screen Back Button Does Not Fire OnBackButtonPressed in Android on GitHub. When you run it on Windows instead of Android, OnBackButtonPressed-Event can be reached. But for Android, it can't. You can follow up this issue.

huangapple
  • 本文由 发表于 2023年3月9日 23:08:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75686462.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定