WPF Button – Method when pressed


I want to call a method when a button is in the mouse down state (IsPressed) and call another method when it is released. I can't seem to figure out a simple way to do this.


Best Solution

If you're in a situation in which you can use bindings, set a OneWayToSource binding on the IsPressed property of the button. When the source property changes, execute your code.

This should work regardless of how the button is pressed.