Search code examples
xamarin.formsswipe-gesture

Is there a way to disable Xamarin Forms SwipeGestureRecognizer on Desktop?


I have a Xamarin Forms app and I wonder if it's possible to allow SwipeGestureRecognizer only for Phones (or small screens).

I'm using a view with 2 content views. On Desktop I want to see both at screen, but on Phone I want to see them individually (swipe gesture).

        <ContentView.GestureRecognizers>
            <SwipeGestureRecognizer Command="{Binding SwipedViewCommand}" Direction="Right" />
        </ContentView.GestureRecognizers>

The command inverts the value of a boolean, and each content view is visible binded to that boolean (one checking for true, the other one to false)

https://learn.microsoft.com/es-es/xamarin/xamarin-forms/app-fundamentals/gestures/swipe


Solution

  • There is an issue on XF: https://github.com/xamarin/Xamarin.Forms/issues/8756

    In the meantime, you can set CanExecute of Command:

    new Command(() => { }, () => Device.Idiom == TargetIdiom.Phone);