RadRangeSlider SelectionChanged Event

7 posts, 0 answers
  1. Josh
    Josh avatar
    5 posts
    Member since:
    Aug 2013

    Posted 14 Sep Link to this post

    I noticed that there is no RadRangeSlider.SelectionChanged event. Is there another event (or multiple events) that would be raised when either the SelectionStart or the SelectionEnd have changed?

    I know I could use something like:

    RegisterPropertyChangedCallback(KioskRangeSlider.SelectionStartProperty, OnSelectionChanged)

    But that introduces some problems of its own and I'd prefer an event on the RadRangeSlider.

    I'm using 2016.2.711.45 and I now realize that there is a newer version, but I don't see any documentation about whether 2016.3 adds this functionality.

    Thanks.

  2. Josh
    Josh avatar
    5 posts
    Member since:
    Aug 2013

    Posted 14 Sep in reply to Josh Link to this post

    Well look at that! v2016.3.914.45 does in fact add a RadRangeSlider.SelectionChanged.

    Thanks for the pre-emptive addition, Telerik! :)

  3. DevCraft banner
  4. Josh
    Josh avatar
    5 posts
    Member since:
    Aug 2013

    Posted 14 Sep in reply to Josh Link to this post

    Perhaps I celebrated too soon. While there is a new SelectionChanged event on the RadRangeSlider, it does not seem to be raised under any of the scenarios I tried: Change Start, Change End, Drag Range.

    Is there something special needed for this event to be raised or is it a bug?

  5. Vladislav
    Admin
    Vladislav avatar
    276 posts

    Posted 15 Sep Link to this post

    Hi Josh,

    Thank you for contacting us.
    Can you please assure that you are using RadRangeSlider for UWP control, from the UI for Universal Windows Platform suite? Since this control doesn't have such event (SelectionChanged)? 

    Regards,
    Vladislav
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Josh
    Josh avatar
    5 posts
    Member since:
    Aug 2013

    Posted 15 Sep in reply to Vladislav Link to this post

    Hi Vladislav,

    You are right, I started with a clean project and realized that the SelectionChanged event was due to some other testing and code I had added. 

    So back to the original question, is there a recommended approach for an event on the change of the Start or End value? For now, I'd prefer to use something native to the RangeSlider control, but perhaps I'll need to use an attached property on SelectionStart and SelectionEnd to raise a custom event.

  7. Josh
    Josh avatar
    5 posts
    Member since:
    Aug 2013

    Posted 15 Sep Link to this post

    I ended up implementing my own SelectionChanged event.

    In case anyone is interested...

    First, derive a control from RadRangeSlider and include two new Dependency Properties (I used CustomStartValue, CustomEndValue). These will be bound on the control to raise DependencyPropertyChanged events.

    When the DependencyProperty changes, we can then raise a SelectionChanged event on the CustomRangeSlider.

    public class CustomRangeSlider : RadRangeSlider
    {
        public event EventHandler SelectionChanged;
     
        #region Custom Start/End Properties for Change event binding
     
        public static readonly DependencyProperty CustomStartValueProperty =
            DependencyProperty.Register(nameof(CustomStartValue),
                    typeof(double),
                    typeof(CustomRangeSlider),
                    new PropertyMetadata(0.0d, ValueChanged));
     
        /// <summary>
        /// Bindable property to listen for SelectionChanged events
        /// </summary>
        public double CustomStartValue
        {
            get { return (double)GetValue(CustomStartValueProperty); }
            set { SetValue(CustomStartValueProperty, value); }
        }
     
        public static readonly DependencyProperty CustomEndValueProperty =
            DependencyProperty.Register(nameof(CustomEndValue),
                    typeof(double),
                    typeof(CustomRangeSlider),
                    new PropertyMetadata(0.0d, ValueChanged));
     
        /// <summary>
        /// Bindable property to listen for SelectionChanged events
        /// </summary>
        public double CustomEndValue
        {
            get { return (double)GetValue(CustomEndValueProperty); }
            set { SetValue(CustomEndValueProperty, value); }
        }
     
        #endregion
     
        public CustomRangeSlider()
        {
        }
     
        private static void ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var slider = d as CustomRangeSlider;
            slider.OnSelectionChanged();
        }
     
        public void OnSelectionChanged()
        {
            SelectionChanged?.Invoke(this, EventArgs.Empty);
        }
    }

    The above is just a simple implementation. You can further extend this by using SelectionChangedEventArgs and pass through the old/new values.

    Then, in XAML, use the new CustomRangeSlider control and bind  the Dependency Properties to the SelectionStart and SelectionEnd properties on the control. 

    <controls:CustomRangeSlider x:Name="myRangeSlider"
               SelectionStart="{x:Bind ViewModel.SliderMin, Mode=TwoWay}"
               SelectionEnd="{x:Bind ViewModel.SliderMax, Mode=TwoWay}"
               CustomStartValue="{x:Bind myRangeSlider.SelectionStart, Mode=OneWay}"
               CustomEndValue="{x:Bind myRangeSlider.SelectionEnd, Mode=OneWay}">
    </controls:CustomRangeSlider>

    You can still bind SelectionStart and SelectionEnd to ViewModel property, but these new Dependency Properties will listen for changes to either and raise the SelectionChanged event.

    Hope this helps.

    Josh

  8. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    138 posts

    Posted 15 Sep Link to this post

    Hello Josh,

    We do have "RangeSelectionChanged" event handlers feature request on the backlog for the RadRangeSlider. However, we cannot promise a specific time frame for it's implementation. If you'd like to publicly add it to our feature request site and vote it up, you can do so here.

    What you have posted below is a good approach for those whom are not using MVVM and want an event fired when the value changes, thank you for sharing. 

    Regards,
    Lance | Tech Support Engineer, Sr.
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner