Transfer control to another wpf control during mousedown

354 Views Asked by At

This time I have a hard one for you :-)

Currently I am about to develop a usercontrol in wpf. I want this control to open up a slider as soon as one presses the mousebutton on a specific button within this control. The user should be able to move this slider as long as the mousebutton is still pressed.

As soon as the user releases the mousebutton the slider should disappear.

I already have a solution for this, but it's a very hacky one, because I am doing it through screen coordinates.

Is there any way to do this in a pleasant way with WPF?

Any help is highly apprechated!

Regards, Michael

1

There are 1 best solutions below

3
On

Please answer these questions first

  1. What is your current XAMl and code behind?
  2. While pointer of the slider is getting dragged along its length, do you want the button to be kept pressed all the time?
  3. If so, did you use ToggleButton because it can be pressed throughout and can be toggled (unpressed) when you set its IsChecked property to false (i.e. when user releases mousebutton).
  4. Have you checked mouse button state as Pressed (from button event args e) when mouse moves, being dragged, over some element such as the slider here?

e.g.

    e.LeftButton == MouseButtonState.Pressed

EDIT

Related to point no. 2....

The reason why I suggest ToggleButton is because only that can be kept pressed while you slide on the slider. Otherwise with normal button, you can open the slider popup on button click but the button will loose its Pressed state when you move onto the slider.

Further, the IsChecked property of the ToggleButton can be two way bound to the IsOpen property of the slider popup. This way when the user stops sliding and releases the mouse, we can set IsOpen of the popup as false and that will automatically unpress the togglebutton due to that two way binding.