Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide the left menu on tap anywhere on android screen xamarin forms?

I am working on xamarin forms. I am using Master detail page to open left menu. And its working fine. Right now menu hide only when user click on menu icon on top. But I want if menu is open, then if user click anywhere on screen, menu should hide.

How I can do this?

like image 683
anand Avatar asked Oct 29 '22 21:10

anand


1 Answers

I've managed to do it using a custom renderer.

[assembly: ExportRenderer(typeof(BaseMasterDetailPage), typeof(MyMasterDetailPageRenderer))]

namespace Driver.Droid.Renderers
{
    public class MyMasterDetailPageRenderer : MasterDetailPageRenderer
    {
        public override bool OnTouchEvent(Android.Views.MotionEvent e)
        {
            if (e.Action == Android.Views.MotionEventActions.Up)
                new Task(CloseDrawers).Start(TaskScheduler.FromCurrentSynchronizationContext());

            return base.OnTouchEvent(e);
        }
    }
}
like image 98
JimBobBennett Avatar answered Nov 15 '22 05:11

JimBobBennett