How to stop update value of slider while dragging it?

后端 未结 5 2445
遥遥无期
遥遥无期 2021-02-20 12:21

I\'ve slider that its value is bind to some property, and the property updates it all the time. While dragging the [thumb on] slider I want to stop this update value of slider f

5条回答
  •  忘了有多久
    2021-02-20 13:03

    Added a flag to indicate dragging and only send out value changed events when the slider is being dragged.

     public class CustomSlider:Slider
    {
    
        public bool IsDragging { get; protected set; }
        protected override void OnThumbDragCompleted(System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            IsDragging = false;
            base.OnThumbDragCompleted(e);
    
        }
    
        protected override void OnThumbDragStarted(System.Windows.Controls.Primitives.DragStartedEventArgs e)
        {
            IsDragging = true;
            base.OnThumbDragStarted(e);
        }
    
        protected override void OnValueChanged(double oldValue, double newValue)
        {
            if (!IsDragging)
            {
                base.OnValueChanged(oldValue, newValue);
            }
        }
    }
    

提交回复
热议问题