use*_*961 6 c# xaml xamarin xamarin.forms
我试图阻止我的应用程序的用户按下硬件后退按钮。我在 xaml 文件后面的代码中找到了这个代码片段:
protected override bool OnBackButtonPressed()
{
return true;
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了这种方法的变体,包括使用 Boolean 而不是 Bool 并且不返回base.functionname任何内容似乎会触发此方法。这是更大的背景:
后面的代码:
namespace Watson.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class StartScan : ContentPage
{
public StartScan()
{
InitializeComponent();
}
protected override bool OnBackButtonPressed()
{
return true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是堆栈中的第二页,禁用按钮只需要在此页面上发生,其他地方不需要。
任何帮助,将不胜感激。
这对我有用,我在 Android 和 iOS 平台上使用 Xamarin.Forms 进行了尝试。
希望你能用这段代码解决。
namespace Test
{
public partial class TestPage2 : ContentPage
{
public TestPage2()
{
NavigationPage.SetHasBackButton(this, false);
InitializeComponent();
}
protected override bool OnBackButtonPressed()
{
//return base.OnBackButtonPressed();
return true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢,
| 归档时间: |
|
| 查看次数: |
5612 次 |
| 最近记录: |