Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Slider event which occurs only when the value is changed by the user

I am making a music player in which I need to create a seek. Now I have done it in WinForms with a TrackBar in this way:

  • Use a Timer to keep the position of the media and the value of the TrackBar synced.
  • Use the Scroll event to change the media position when the user drags the TrackBar's thumb.

But in WPF, there is no Scroll event and the ValueChanged event fires even when the value is changed in code. So, when I use a DispatcherTimer to update the slider position, even then the ValueChanged event is fired which in turn changes the media position. As a result, the media doesn't play properly.

So I need an Event which fires only when the value of a Slider is changed by the user.

I have already come across this question but it doesn't have a proper answer.

Any help will be appreciated. Thanks in anticipation.

like image 296
Fᴀʀʜᴀɴ Aɴᴀᴍ Avatar asked Nov 08 '22 22:11

Fᴀʀʜᴀɴ Aɴᴀᴍ


1 Answers

In your ValueChanged event-handler, check for some properties to see for user interaction.

IsFocused, IsMouseDirectlyOver, IsMouseOver, IsKeyboardFocused, IsKeyboardFocusWithin 
like image 149
AnjumSKhan Avatar answered Nov 14 '22 23:11

AnjumSKhan