Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a Button's tab stop dashed border color in WPF?

In keyboard navigation, when a button is selected, it has a dashed border. How to change its color?

like image 576
Jader Dias Avatar asked Jul 06 '11 13:07

Jader Dias


1 Answers

I believe what you are looking for is the FocusVisualStyle. If you set this to null, you can hide the dashed border. In your case, you want to change the color. What you would do would be to create a new style and apply it to the FocusVisualStyle.

Here is an MSDN article that shows you how to do this:

http://msdn.microsoft.com/en-us/library/ms744790.aspx

The basic code they list is as follows:

<Page.Resources>
  <Style x:Key="MyFocusVisual">
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate>
          <Rectangle Margin="-2" StrokeThickness="1" Stroke="Red" StrokeDashArray="1 2"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</Page.Resources>
<StackPanel Background="Ivory" Orientation="Horizontal">
  <Canvas Width="10"/>
  <Button Width="100" Height="30" FocusVisualStyle="{DynamicResource MyFocusVisual}">
    Focus Here</Button>
  <Canvas Width="100"/>
  <Button Width="100" Height="30" FocusVisualStyle="{DynamicResource MyFocusVisual}">
    Focus Here</Button>
</StackPanel>
like image 114
IAmTimCorey Avatar answered Oct 15 '22 03:10

IAmTimCorey