Xamarin.Forms Slider iOS gesture failure

2019-08-31 01:59发布

问题:

When I try to use the Slider on iOS it slides out the Master menu. It works fine on Android.

One option would be to disable gestures all together but I haven't found a way to disable them for only that page. I would very much like to keep the sliding gestures for the other pages without sliders.

回答1:

It sounds like your slider may be too close to edge of the page. If your design allows it, try adding a margin to the left and right of the slider.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:SliderTest"
             x:Class="SliderTest.MainPage">
   <StackLayout Orientation="Vertical" VerticalOptions="Center">
     <Slider Margin="10,0,10,0"/>
   </StackLayout>
</ContentPage>

And in case you need separate margins for iOS and Android, you can do that like this:

  <StackLayout Orientation="Vertical" VerticalOptions="Center">
    <Slider>
      <Slider.Margin>
        <OnPlatform x:TypeArguments="Thickness" iOS="10,0,10,0" Android="20,0,20,0"/>
      </Slider.Margin>
    </Slider>
  </StackLayout>