I want to globally deactivate the focus rectangles in my WPF application. For single controls that can be done via
<Style TargetType="Button">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
but how to apply it to all controls in my application. When applying to FrameworkElement nothing happens. What I need would be something like "apply to class x and all derived classes".
Thanks in advance,
Stefan
This may not be simple, but you could write a function that alters the existing style of a control. Once that is written, you could write a function that recursively alters the style of each element.
You can use OverrideMetadata:
I stumbled upon this as well and came up with this (indeed not very nice but effective) solution:
In my MainWindow's constructor I then just call
FocusVisualStyleRemover.Init();
According to http://msdn.microsoft.com/en-us/library/bb613567.aspx, you should be able to set global focus style like this:
I haven't tested it, but I guess that when you empty the controltemplate, this would effectively disable the focus rectangle for the whole app (provided you include this style in app.xaml).
Looks like there's no magic bullet for this:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/141c8bfa-f152-4f8a-aca0-3c3b5440d183
Part of the default
Template
for theWindow
class is anAdornerDecorator
. If you override theWindow
's defaultTemplate
to not include anAdornerDecorator
, theFocusVisualStyle
on all controls will not appear.Even if a
Control
has a validFocusVisualStyle
that sets aTemplate
, it will not appear without theAdornerDecorator
.An easy way to accomplish this is to include this
Style
in your App.xaml file underApplication.Resources
.