[FIXED] How could I close my sidebar without closing my app in C# xamarin forms android?

Issue

I’m working with C# xamarin forms android and I’m trying to close my sidebar when the user touches de backbuttom but I’m not able to do it. Instead, my aplications closeses.

HomePage.xaml.cs code:

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

my sidebar AppShell.xaml.cs code:

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;
        }
}

Image of my app:

enter image description here

How could I resolve that?
Thank tou very much!

Solution

The easiest way that do this is to set the flyout presented property.

Try something like this:

   Shell.Current.FlyoutIsPresented = false;   

Good luck!

Answered By – FreakyAli

Answer Checked By – Mary Flores (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published