在C# xamarin forms android中,如何在不关闭应用的情况下关闭侧栏?

o2rvlv0m  于 2022-12-07  发布在  C#
关注(0)|答案(1)|浏览(165)

我正在使用C# xamarin窗体android,当用户触摸后台按钮时,我试图关闭我的侧边栏,但我无法做到。相反,我的应用程序关闭了。
代码:

public partial class HomePage : ContentPage
{
    string[] subs;
    public HomePage()
    {
        //NavigationPage.SetHasBackButton(this, false);
        InitializeComponent();
    }
    protected override bool OnBackButtonPressed()
    {
        return true;
    }
}

我的侧边栏AppShell.xaml.cs代码:

public partial class AppShell : Xamarin.Forms.Shell
    {
        public AppShell()
        {
            InitializeComponent();
            nameuser.Title = Preferences.Get("displayName", "Default");
            versionadoAPP.Text = "v" + $"{VersionTracking.CurrentBuild}.{VersionTracking.CurrentVersion}";
        }
        protected override bool OnBackButtonPressed()
        {
            return true;
        }
}

我的应用程序图片:

我该怎么解决呢?非常感谢你!

wh6knrhe

wh6knrhe1#

执行此操作的最简单方法是设置弹出型按钮的“显示”特性。
请尝试以下操作:

Shell.Current.FlyoutIsPresented = false;

祝你好运!

相关问题