3
votes

I am trying to create a media player and I can't figure out how to detect a user moving the slider for the media position. I have tried the various events MS gives for the slider but none of them seem to fire. I have seen guides for earlier version of WP that show Thumb.Drag events but I don't see those on WP 8.1. How can I detect the slider moving?

Thanks

Slider Control

2
ValueChanged event I'd think would be one way.Chris W.
Yes but how would that work with a DispatchTimer that is moving the slider as the media is playing? My thought was that the DispatchTimer event would need to check if the slider is being moved already before setting the current position as the two actions would be competing. Is that not true?Nic Clarkson
Ah ok, sorry I see what you're saying now. Yea I'd have to actually think about that one since I wouldn't imagine just watching the thumb would suffice anyway since the user can click anywhere in the track also to rev/ffwd, good question +1Chris W.

2 Answers

0
votes

What works for me is using PointerPressed to determine if the user is interacting with the slider and then I use PointerReleased, PointerExited and PointerCaptureLost for the opposite case.

If your DispatchTimer always changes your slider value by the same amount each time, then you can use the ValueChanged event to determine whether the value changed is different to what your DispatchTimer is applying. This is where you can handle your user-input logic (pausing the timer until one of the events I mentioned above occurs).

0
votes

I had the very same issue. The range bar would replace a progressBar so the user could interact with it and jump the media to a specific time. A event that I could capture user interaction but wont be fired by programmatically changes is GotFocus as in:

Xaml:

<Slider x:Name="sldTest" HorizontalAlignment="Left" Margin="-3,40,0,0" VerticalAlignment="Top" Width="379" GotFocus="Slider_GotFocus"/>

C#:

    private void Slider_GotFocus(object sender, RoutedEventArgs e)
    {
       // the new value will be at the very same object, so you can just 
       // get the value of itself.
       var newValue = sldTest.Value;
    }