Move to Point and range selection issue

4 posts, 1 answers
  1. Nicole
    Nicole avatar
    30 posts
    Member since:
    Mar 2011

    Posted 14 Feb 2012 Link to this post

    We have a RadSlider defined as follows:

    <telerik:RadSlider x:Name="sldTimeSelection" Grid.Row="1" Grid.Column="0" Orientation="Horizontal"  
                       Minimum="-365" Maximum="0" IsMoveToPointEnabled="True"
                       IsSelectionRangeEnabled="True" MinimumRangeSpan="7" MaximumRangeSpan="365" 
                       SelectionStart="-30" SelectionEnd="0"
                       IsSnapToTickEnabled="True" TickPlacement="BottomRight" Ticks="-7, -30, -90, -180, -365" EnableSideTicks="False" Margin="5,0" >
    </telerik:RadSlider>

    Move to Point works perfectly with the mouse when expanding the slider range in the decrease direction.  However, if you click inside the range itself, neither handle moves.  This makes sense, since the control has no way of knowing which handle you want to move.  However, I want to lock the increase handle (per my other thread) and allow the user to click inside the range to move the decrease handle to a high value.

    For example, the slider starts at -30 to 0.
    I click on/near the -90 tick and the range is now -90 to 0, which is good.
    I click on/near the -30 tick, and the range does not move.  The desired behavior is for the range to become smaller at -30 to 0.

    Is this possible?
  2. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 16 Feb 2012 Link to this post

    Hi Nicole,

    With a little bit of code I managed to implement the scenario you're looking for. Could you please take a look at the attached project and let me know if it works for you.

    All the best,
    Kiril Stanoev
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Nicole
    Nicole avatar
    30 posts
    Member since:
    Mar 2011

    Posted 16 Feb 2012 Link to this post

    This works beautifully, thanks!

  5. Nicole
    Nicole avatar
    30 posts
    Member since:
    Mar 2011

    Posted 27 Feb 2012 Link to this post

    A quick modification for posterity -- the additional lines prevent mouse clicks which are in the window but not on the control from moving the slider.

    private void Slider_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        var frameworkEl = e.OriginalSource as FrameworkElement;
        if (frameworkEl != null)
        {
            var container = frameworkEl.ParentOfType<RadSlider>();        
            if (container != null)
            {
                var width = container.ActualWidth;
                var mousePosition = e.GetPosition(this.sldTimeSelection);
                var value = ((this.sldTimeSelection.Maximum - this.sldTimeSelection.Minimum) * (mousePosition.X - width)) / width;
                this.sldTimeSelection.SelectionStart = this.SnapToTick(value);
            }
        }
    }
Back to Top