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

Finding where the user moved from

2 Answers 35 Views
Slider
This is a migrated thread and some comments may be shown as answers.
PaulH
Top achievements
Rank 1
PaulH asked on 20 Dec 2012, 12:04 PM
Hi there.

I have a Silverlight app that makes use of a Slider, bound to the current time position of a media item. I want to track the user's use of the system for analytics. One such event is when a user clicks on the slider to move to a new position. I've been using the MouseLeftButtonDown event but with that I can only determine where the user has moved the slider to and not where it's come from. I need to know both values. I had tried setting a flag in the MouseLeftButtonDown event and then checking that in the ValueChanged event but by the time ValueChanged fired the old and new values were a fraction apart and at a position after where the user had clicked to. I don't want to simply rely on the ValueChanged event as that fires so frequently and I need to know only when the user has manually moved position. Is there a way to determine what the position was that the user moved from?

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Accepted
Kiril Vandov
Telerik team
answered on 21 Dec 2012, 04:17 PM
Hello Paul,

It is possible to get the previous position using the ValueChanged  event but as you mentioned it fires too quickly and implementing logic to calculate the previous position could cause performance issues.
private const int updateTime = 1;
private
void RadSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    currentVideoPosition = slider.Value;
 
    if (currentVideoPosition - previousVideoPosition < updateTime)
    {
        previousVideoPosition = currentVideoPosition;
    }
}
And then when you click you will have the two values.

However there is another approach. Basically , RadSlider is mainly consisted of RepeatButton, Thumb, and second RepeatButton. You acntually see these three when you use RadSlider with no additional properties set.
So you could get these Repeat buttons from the template of RadSlider. Then, in their Click event handlers, get the RadSlider Value property and store it in field. After that the ValueChanged event will update the Slider's Value and then the Slider's MouseLeftButtonDown event will be triggered.

I am attaching you a sample project for your convenience.

Hope this information help.

Kind regards,
Kiril Vandov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
PaulH
Top achievements
Rank 1
answered on 24 Dec 2012, 11:40 PM
Hi and thanks. I've implemented your suggestions and it's now doing what I want. Excellent.

And a Merry Christmas and Happy New Year to all.
Tags
Slider
Asked by
PaulH
Top achievements
Rank 1
Answers by
Kiril Vandov
Telerik team
PaulH
Top achievements
Rank 1
Share this question
or