Home > Mobile >  Xamarin.Forms Slider, Value or Minimum not working
Xamarin.Forms Slider, Value or Minimum not working

Time:11-04

I have a slider like so:

<Slider x:Name="questionsSlider" ValueChanged="questions_ValueChanged" Maximum="30" Minimum="10" Value="10" MaximumTrackColor="Orange" MinimumTrackColor="Orange" ThumbColor="#fa5156"></Slider>

I am expecting my slider to be at 10, but its at 0 when it loads. This is how it looks:

enter image description here

What am I doing wrong, here is my questions_ValueChanged method:

void questions_ValueChanged(System.Object sender, Xamarin.Forms.ValueChangedEventArgs e)
        {
            var newStep = Math.Round(e.NewValue / step);
            questionsSlider.Value = newStep * step;
            questions = newStep * step;
            questionsLabel.Text = "Number of Questions: "   questions.ToString();
        }

For those who are wondering step is a double and has a value of 10.0

CodePudding user response:

I think you're misinterpreting what you are seeing. Since you set Minimum="10" in your xaml that means that when the slider is all the way to the left, its value is 10. Just as you are seeing.

If the value of the slider was 0 the text of your label would be "Number of Questions: 0".

  • Related