Forum Xamarin.Forms

Slider OnValueChanged Not Called On First Click: Any Workaround? [Testing on Android]

NickprovsNickprovs USMember ✭✭
edited September 2017 in Xamarin.Forms

Hi there,

I searched for a topic like this, and there exists two... but they are quite old and no one seems to have posted a workaround.

I have a slider on my main page. I see their values via a data bound label. If you hold and slide the slider, the value will change. However, if you only tap the slider-- the circle's position will move but the slider value will remain 0. A second tap will work just fine.

Here's a screenshot where I tapped two sliders for the first time. You can see the circle has moved but the value remained the same.

https://i.imgur.com/oV64Kb4.png

Here's my XAML, but I doubt it's worth looking at...

    <Label HorizontalOptions="Center" VerticalOptions="Center" Text="{Binding 
        Source = {x:Reference slider1}, 
        Path=Value, 
        StringFormat = 'Frequency is {0:0} Hertz' }" x:Name="label1"></Label>
    <Slider Minimum="0" Maximum="5000" x:Name="slider1"></Slider>

    <Label  HorizontalOptions="Center" VerticalOptions="Center" Text="{Binding 
        Source = {x:Reference slider2}, 
        Path=Value, 
        StringFormat = 'Amplitude is {0:0} Meters' }" x:Name="label2"></Label>
    <Slider Minimum="0" Maximum="32760" x:Name="slider2"></Slider>

Thanks for checking the thread out,

Nick

Best Answer

Answers

  • MatteoPiccioniMatteoPiccioni USMember ✭✭
    edited March 2018

    Hello,
    its a xamarin form bug.

    Solution for me was:

    #if __ANDROID__
    
                // BUG: https://bugzilla.xamarin.com/show_bug.cgi?id=54887
                //      Should be fixed on 2.6.0-pre1
    
                mySlider.Value = 1;
                Device.StartTimer(TimeSpan.FromMilliseconds(100), () =>
                {
                    mySlider.Value = 0;
                    return false;
                });
    
    #endif
    
Sign In or Register to comment.