I need to control video position (and also document page in another case) with a slider. But problem is that I don't know how to decide if a slider value vas changed by user (click, thumb drag...), or from binding. It is possible to fire some event only when slider value is updated from UI, not from binding?
I've implemented a custom slider:
public class NotifyingSlider : Slider
{
public static readonly DependencyProperty ValueChangedFromUIProperty =
DependencyProperty.Register("ValueChangedFromUI", typeof(ICommand), typeof(NotifyingSlider));
public ICommand ValueChangedFromUI
{
get
{
return (ICommand)GetValue(ValueChangedFromUIProperty);
}
set
{
SetValue(ValueChangedFromUIProperty, value);
}
}
protected override void OnThumbDragCompleted(DragCompletedEventArgs e)
{
base.OnThumbDragCompleted(e);
ValueChangedFromUI?.Execute(null);
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
ValueChangedFromUI?.Execute(null);
}
}
But ValueChangedFromUI
command is executed only when user drag a thumb to the specific position or click on bar exactly to the position of tick. When user click between two ticks (so value/thumb is moved to the nearer one), command is not executed - this is a main problem for me.