WPF: Slider doesnt raise MouseLeftButtonDown or MouseLeftButtonUp

后端 未结 4 1993
傲寒
傲寒 2021-01-04 01:02

I tried this XAML:



        
4条回答
  •  我在风中等你
    2021-01-04 01:29

    Another way to do it (and possibly better depending on your scenario) is to register an event handler in procedural code like the following:

    this.AddHandler
    (
        Slider.MouseLeftButtonDownEvent,
        new MouseButtonEventHandler(slider_MouseLeftButtonDown),
        true
    );
    

    Please note the true argument. It basically says that you want to receive that event even if it has been marked as handled. Unfortunately, hooking up an event handler like this can only be done from procedural code and not from xaml.

    In other words, with this method, you can register an event handler for the normal event (which bubbles) instead of the preview event which tunnels (and therefore occur at different times).

    See the Digging Deeper sidebar on page 70 of WPF Unleashed for more info.

提交回复
热议问题