How to stop update value of slider while dragging it?

后端 未结 5 2449
遥遥无期
遥遥无期 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:08

    The template for Slider includes a Thumb, which raises the ThumbDragDelta event as the mouse is moved. Slider will always update the bound value immediately when it receives a ThumbDragDelta event.

    The trick is to stop this event. The easiest way is to subclass Slider:

    public class SliderIgnoreDelta : Slider
    {
      protected override void OnThumbDragDelta(DragDeltaEventArgs e)
      {
        // Do nothing
      }
    }
    

    This slider will not update the value until the thumb drag completes.

    Another solution is to intercept the ThumbDragDelta event on the Thumb. If you happen to be re-templating the Slider anyway, this might be a better solution. For example if you already have an EventBlocker class coded up that sets Handled true on the given RoutedEvent, you could put this in your template:

    
      
    
    

    But for most cases you'll probably want to go with my first solution.

提交回复
热议问题