SfSlider OnChange event not working for object property value

I have a slider like so;


<SfSlider ID="SliderTF" Min="0" Max="60" @bind-Value="@graphicsSettings.TargetFrameRate" Type="SliderType.MinRange">
<SliderTicks Placement="Placement.After" Format="N0" ShowSmallTicks="true" LargeStep="6" SmallStep="3"></SliderTicks>
<SliderEvents TValue="int" OnChange="setTargetFrameRate"></SliderEvents>
</SfSlider>

The OnChange method setTargetFrameRate is never reached, but if i change the @bind-value to a local property such as a `private int TargetFrameRate` that is same type as graphicsSettings.TargetFrameRate, it does work. This means i had to make local copies for all the graphics settings properties. When looking at graphicsSettings.TargetFrameRate its values do change when binded to the slider, but it just doesn't seem to call the OnChange event. 

I'm wondering if maybe this is because in my object, TargetFrameRate can be null?
If it is needed, the class can just be:

public class GraphicsSettings 
{
public int TargetFrameRate { get; set; }
}
Then in class GraphicsSettings graphicsSettings = new GraphicsSettings();
graphicsSettings.TargetFrameRate = 60;

3 Replies 1 reply marked as answer

IL Indhumathy Loganathan Syncfusion Team February 8, 2022 02:30 PM UTC

Hi Dylan, 
 
Greetings from Syncfusion support. 
 
We have prepared a Blazor Slider sample with a shared code snippet. The OnChange event of the Slider component will be triggered for UI level changes only, not for dynamic value changes. In other words, this event will be triggered while you drag the slider thumb in the UI. We have included an example for your convenience. 
 
 
Please check the sample and if we have misunderstood, replicate your exact issue in the shared sample. These details would help us to assist you promptly. 
 
Regards, 
Indhumathy L 



DG Dylan Goerke February 9, 2022 06:32 AM UTC

Thank you very much for your help! 

I found one minor hiccup however, the OnChange event seemed to call as soon as the value binded by the @bind-value changed. This meant that on the method call, it would have the previous value. If i added a await Task.Delay(1000) it would then have the correct value. But i found the best way was to just use the SliderChangeEventArgs.

And i think the original issue i was having was because my properties were nullable, so after making TValue="int?" the OnChange event worked. 

This was what my code ending up looking like:



Marked as answer

IL Indhumathy Loganathan Syncfusion Team February 10, 2022 05:30 AM UTC

Hi Dylan, 
 
Thanks for the update. We are happy to hear that the issue is resolved. Please get back to us if you need any further assistance.  
 
Regards, 
Indhumathy L 


Loader.
Up arrow icon