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:
<Trigger Property="IsFocused" Value="true">
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="BorderThickness" Value="1" />
</Trigger>
You should use a Style
tag, if you want to apply this style for a particular control type (use TargetType="{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 BasedOn
attribute:
<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".
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