I am working on a WPF application having lots of screens and every screen has lots of controls on it.
It becames very difficult to determine which control has focus.
So i want to highlight the control that currently have focus on it. It could be textbox, button, combobox, listbox or grid.
It’ll be better if we could do this using styles and triggers.
Thanks
You should use a trigger for the right event. In your case it’s
IsFocused. Simple example:You should use a
Styletag, if you want to apply this style for a particular control type (useTargetType="{x:Type TextBox}", for example).If you want to apply to all control types in your application, than you should consider using a base style with only such kind of trigger and than just inherit it in your custom styles with a help of
BasedOnattribute:<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource BaseFocusStyle}">Good example of how to do this is a SO question: “How to make Style.Triggers trigger a different named style to be applied“.