This is a migrated thread and some comments may be shown as answers.

Radslider with different smallchange

5 Answers 112 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Hen
Top achievements
Rank 1
Veteran
Hen asked on 07 Feb 2021, 07:40 AM

Hi,

 

I need to bind the increasesmall and decreasesmal to 2 different smallchange.

Is it possible?if not there is a way that the increasesmall/decreasesmall will increase/decrease with 2 different stepvalue.

Thank you.

5 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 10 Feb 2021, 01:05 PM

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/.

0
Hen
Top achievements
Rank 1
Veteran
answered on 14 Feb 2021, 08:56 AM

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.

0
Dinko | Tech Support Engineer
Telerik team
answered on 15 Feb 2021, 02:34 PM

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/.

0
Hen
Top achievements
Rank 1
Veteran
answered on 02 Mar 2021, 09:41 AM

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.

0
Dilyan Traykov
Telerik team
answered on 04 Mar 2021, 02:57 PM

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/.

Tags
Slider
Asked by
Hen
Top achievements
Rank 1
Veteran
Answers by
Dinko | Tech Support Engineer
Telerik team
Hen
Top achievements
Rank 1
Veteran
Dilyan Traykov
Telerik team
Share this question
or