I need to trigger an event when the WPF button is pressed (using the mouse, keyboard, touch screen, etc.) and to trigger an event when the WPF buttons are not pressed.
How to do it? It should be easy, but I cannot find how to do it.
You can get from Button and override the OnIsPressedChanged method and fire a special event there.
Or you can bind to the ButtonBase.IsPressed property .
Another option is to use DependencyPropertyDescriptor:
var descriptor = DependencyPropertyDescriptor.FromProperty(Button.IsPressedProperty, typeof(Button)); descriptor.AddValueChanged(this.button, new EventHandler(IsPressedChanged));
If you use MVVM, you can use event triggers to solve your problem. That way, you can still separate your user interface requirements from your application logic.