how can I find if an event is raised by UI or by code? I need to recognaize if Value of a slider is changed by the user from UI or has a new value from the executed code?
Thanks!
how can I find if an event is raised by UI or by code? I need to recognaize if Value of a slider is changed by the user from UI or has a new value from the executed code?
Thanks!
I'm assuming that you've got your Slider
hooked up to a two-way binding where the current value of the slider could thus be determined either by the user dragging the slider Thumb
or by the bound class's code changing the value of the property that the slider is bound to. If this is true, then I think an approach that could work is if you use a handler for the Slider Thumb's DragCompleted
event. Although I've not tried this, I believe this will work because it would seem that the Thumb will only be "dragged" by the user, rather than your executing code changing the value that the slider is bound to (although I concede that this will cause the Thumb to "move" so this will require testing to verify). You will register your handler for this event in the constructor in your code-behind.
See the answers by YotaXP and Santo for some more guidance from this similar question.
As Thumb's DragCompleted event does not address the case that user clicks on slider, I used something similar to what Peter suggesetd in link, I used PreviewMouseLeftButtonUp event of the slider. This addresses all the cases.