Specifically I want all PasswordBox's using a Style to have the same static KeyDown event handler - would it be possible to somehow set this in the Style they are using rather than setting it on each PasswordBox? (which I am having to do in code behind at the moment as they all point to the same static handler)..
A routed event is an event registered with the WPF event system, backed by an instance of the RoutedEvent class, and processed by the WPF event system. The RoutedEvent instance, obtained from registration, is typically stored as a public static readonly member of the class that registered it.
EventSetter
is your friend. As for the handler - just put it into code-behind (you can create a code-behind for a resource dictionary too - just crate a CS file with the same name as the dictionary and add the class attribute to the resource dictionary XAML).
Small example:
<Style>
<EventSetter Event="KeyDown" Handler="KeyDownHandler"/>
</Style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With