MasterDetailPage main page will not be opened with IsGestureEnabled set to false Xamarin.Forms Android

I have a detailed page working in my application. The standard way to open the main page is to either select the hamburger menu icon or move it to the left. One of my detailed pages is used on the carousel page. Scrolling to the left can therefore open the main page or move the carousel to the left (quite annoying if the wrong event occurs).

To stop the Master page displayed when shifting to the left, I set IsGestureEnabled to false. However, this stops the appearance of the main page. Despite their tactile feedback, when you click on the hamburger menu icon, it does nothing.

Is there a way to make the slide gesture be ignored on the MasterDetailPage, and not the gesture of clicking the icon?

Here's a very simple application with the MasterDetailPage and IsGestureEnabled parameters set to false. The wizard page does not open. https://www.dropbox.com/s/rkm5eph3vr38avm/MasterDetailPageTest.zip?dl=0

+5
source share
2 answers

I came up with a little workaround by creating my own renderer for MasterDetailPage. He must meet my needs now.

public class MyMasterDetailPageRenderer : Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer { public override bool OnTouchEvent(MotionEvent e) { if (IsDrawerOpen(Android.Support.V4.View.GravityCompat.Start)) return base.OnTouchEvent(e); else { if (e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Down) return base.OnTouchEvent(e); else { CloseDrawers(); return true; } } } } 

The assembly must be added outside the namespace:

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

This does not completely solve the problem, but the main page does not open when scrolling.

+1
source

Richard code works for me with some changes

  RootView page; protected override void OnElementChanged( VisualElement oldElement, VisualElement newElement ) { base.OnElementChanged( oldElement, newElement ); page = newElement as RootView; } public override bool OnTouchEvent( MotionEvent e ) { if( IsDrawerOpen( Android.Support.V4.View.GravityCompat.Start ) ) return base.OnTouchEvent( e ); else { if( (e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Move) && (page?.SwipeEnabled ?? false) ) return base.OnTouchEvent( e ); else { CloseDrawers(); return true; } } } 
0
source

Source: https://habr.com/ru/post/1259232/


All Articles