WPF - Can I assign an event in style?

In particular, I want all PasswordBoxs using the style to have the same static KeyDown event handler - can I somehow set this in the style that they use and not set it on every password? (which I need to do in the code behind right now, since they all point to the same static handler).

+6
source share
1 answer

EventSetter is your friend. As for the handler - just put it in the encoding (you can also create code for the resource dictionary) - just collect the CS file with the same name as the dictionary and add the class attribute to the XAML resource dictionary).

A small example:

 <Style> <EventSetter Event="KeyDown" Handler="KeyDownHandler"/> </Style> 
+10
source

Source: https://habr.com/ru/post/888403/


All Articles