Forum Xamarin.Forms

Issue while setting slider thumb at a particular point if slider maximum value is too high?

I am working in xamarin forms. I have slider whose maximum value is more than 200. I want to move the slider thumb at particular point on slider for example at 120, but it becomes very tough to put the thumb at particular point. This happens with large maximum values. If values are less then its working fine.

So is there any solution so that we can move the slider's thumb easily at any point if slider's maximum value is very large?


  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Just set the MVVM binded value to 120.
    Let the control take care of the rest.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    wait... Are you meaning programmatically set the thumb? Or do you mean the USER while using the app is having a hard time sliding to exactly 120?

  • LandLuLandLu Member, Xamarin Team Xamurai

    Slider on Android will show decimal values when you set its maximum value to 200. If you mean this causes your issues you can try my approach below to make your slider only allow integer values.

    <Label Text="{Binding Value, Source={x:Reference MySlider}}"/>
    <Slider x:Name="MySlider" Maximum="200" ValueChanged="MySlider_ValueChanged"/>

    Value changed event:

    private void MySlider_ValueChanged(object sender, ValueChangedEventArgs e)
        if (Device.RuntimePlatform == Device.Android)
            var integerValue = Math.Round(e.NewValue);
            ((Slider)sender).Value = integerValue;

    However it also depends on how width your silder is. If you made a very small slider it is absolute that the slider is hard to be adjusted.

  • AnandDubey.8578AnandDubey.8578 USMember ✭✭

    @ClintStLaurent yes its very hard to sliding exactly at 120. when I try to put it 120, I move to 123 or 118 or 119 or 121. Its very hard to slide it exactly 120.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    How about giving it a smaller range... like 1/10th your need. Then multiple the result by 10.
    Now your range is 1-12 instead of 10-120, and your steps become values of 10 instead of increments of 1.

    Otherwise, you could make a renderer and handle the actual movement and have it jump in increments of 5.

    Or... just round up the value when they are done making a selection.

    It might be worth putting in a feature request to Xamarin. The WPF slider has an additional property of Step or Increment (I forget now) that would let you set the step size to 5 or 10. It would be nice if that were in the Xamarin Slider as well.

Sign In or Register to comment.