5 Answers, 1 is accepted
Hello Hen,
Thank you for your interest in our RadSlider control.
Currently, there is no out-of-the-box way to achieve the desired behavior. What you can try to control these values is to subscribe to the PreviewMouseDown events of the thumbs inside the slider. In the below code snippet, you can see how you can do that. In a few words, depending on the thumb name I am changing the SmallChange and LargeChange values. You can also check the attached project.
public MainWindow()
{
InitializeComponent();
this.slider.Loaded += Slider_Loaded;
}
private void Slider_Loaded(object sender, RoutedEventArgs e)
{
var repatButtons = (sender as RadSlider).ChildrenOfType<RepeatButton>();
if (repatButtons != null)
{
foreach (var button in repatButtons)
{
button.PreviewMouseDown += Button_PreviewMouseDown; ;
}
}
}
private void Button_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var thumb = sender as RepeatButton;
if (thumb.Name == "IncreaseButton")
{
this.slider.SmallChange = 5;
}
else if(thumb.Name == "LargeIncreaseButton")
{
this.slider.LargeChange = 3;
}
else if (thumb.Name == "DecreaseButton")
{
this.slider.SmallChange = 1;
}
else if (thumb.Name == "LargeDecreaseButton")
{
this.slider.LargeChange = 2;
}
}
Regards,
Dinko
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello Dinko,
Thank you for your reply.
How can i implements your solution in a MVVM architecture?
I have a slider that is in a datatemplate and i don't have code behind to do your solution.
Any Suggestions?
Thank you,
Hen.
Hello Hen,
In this case, you can create a custom attached property. You can set it to the RadSlider control. In property changed callback, you can execute the custom logic from my preovus reply. You can check the attached project.
Regards,
Dinko
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello,
What is the smallest value that SmallChange can get?
I get this error: "-0.00610360875867857" is not valid value for property SmallChange when entering this value to SmallChange property.
Thank you.
Hello Hen,
The SmallChange property is actually defined in the RangeBase class from which the RadSlider inherits. Referring to the source code of the class, you can notice that the only requirement for the property is to be a valid positive double.
#region SmallChange Property
/// <summary>
/// The DependencyProperty for the SmallChange property.
/// </summary>
public static readonly DependencyProperty SmallChangeProperty
= DependencyProperty.Register("SmallChange", typeof(double), typeof(RangeBase),
new FrameworkPropertyMetadata(0.1),
new ValidateValueCallback(IsValidChange));
/// <summary>
/// Validate input value in RangeBase (SmallChange and LargeChange).
/// </summary>
/// <param name="value"></param>
/// <returns>Returns False if value is NaN or NegativeInfinity or PositiveInfinity or negative. Otherwise, returns True.</returns>
private static bool IsValidChange(object value)
{
double d = (double)value;
return IsValidDoubleValue(value) && d >= 0.0;
}
With this said, you can remove the - sign from the value to have the code compile successfully.
<telerik:RadSlider SmallChange="0.00610360875867857"
Please let me know if this resolves your issue.
Regards,
Dilyan Traykov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.