0

I need to remove the selected state (effect) or whatever it is called from every control in my interface. You know the black dashed line...

What are the ways for it to be done?

P.S. Is it normal for a fully customized XAML page to use 30MB RAM?

Thanks in advance.

H.B.
  • 166,899
  • 29
  • 327
  • 400
Itay Grudev
  • 7,055
  • 4
  • 54
  • 86

1 Answers1

0

That is controls by the FocusVisualStyle of the associated control. Unfortunately, you cannot disable that globally for all controls using a single Style or setting. Instead, you'd have to individually turn it off for every control type.

For example, you can include the following styles in your Application.Resources to turn it off for the specified controls:

<Style TargetType="Button">
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<Style TargetType="RepeatButton">
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<Style TargetType="ToggleButton">
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<Style TargetType="TreeViewItem">
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<!-- ETC -->

But keep in mind, that if you use the Style property on any of the controls or if you have any other implicit styles defined then those will prevent the styles above from being applied.

Or as Rachel point out, you could do this:

<Style x:Key="FrameworkElementStyleKey" TargetType="FrameworkElement">
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<Style TargetType="Button" BasedOn="{StaticResource FrameworkElementStyleKey}" />
<Style TargetType="RepeatButton" BasedOn="{StaticResource FrameworkElementStyleKey}" />
<Style TargetType="ToggleButton" BasedOn="{StaticResource FrameworkElementStyleKey}" />
<Style TargetType="TreeViewItem" BasedOn="{StaticResource FrameworkElementStyleKey}" />
<!-- ETC -->

Functionally, both approaches above have the same effect.

CodeNaked
  • 40,753
  • 6
  • 122
  • 148
  • 1
    You can simplify the styles further by making a single base style for `FrameworkElement`, which contains `FocusVisualStyle`, and then using single-line control styles which inherit from the base style. There's a good example [here](http://stackoverflow.com/a/7604656/302677) – Rachel Mar 09 '12 at 14:27