如何改变一个按钮的制表位在WPF虚线边框颜色? [英] How to change a Button's tab stop dashed border color in WPF?

查看:870
本文介绍了如何改变一个按钮的制表位在WPF虚线边框颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在键盘导航,当选择一个按钮,它有一个虚线边框。如何改变其颜色?

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

推荐答案

我相信你正在寻找的是 FocusVisualStyle 。如果设置为null,则可以隐藏虚线边框。在你的情况,你想改变颜色。你会做什么是创建一个新样式,并将其应用到 FocusVisualStyle

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.

下面是一个MSDN文章将告诉您如何做到这一点:

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

<一个href="http://msdn.microsoft.com/en-us/library/ms744790.aspx">http://msdn.microsoft.com/en-us/library/ms744790.aspx

基本code他们列出如下:

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>

这篇关于如何改变一个按钮的制表位在WPF虚线边框颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆