In WPF, how do you tell if the left mouse button is currently down without using any events?

Curtis picture Curtis · Apr 18, 2013 · Viewed 21.4k times · Source

I have an app where I want to be able to move a slider. However, the slider is automatically updated by the program every 30 seconds. When I try to change the slider position with my mouse, the program is still updating the slider position, so I cannot move it manually with the mouse.

Somehow, I want the app to NOT update the slider if the user is in the process of changing its position. How can I tell if the left mouse button is down without using the left button down event? I just want to be able to access the mouse, and check the button state of the left mouse button. How do I access it without being inside of a mouse event?

Answer

DanW picture DanW · Feb 9, 2015
bool mouseIsDown = System.Windows.Input.Mouse.LeftButton == MouseButtonState.Pressed;