如何在wpf中全局更改焦点按钮周围虚线的样式? [英] How to change the styling of the dotted line around focused button globally in wpf?

查看:34
本文介绍了如何在wpf中全局更改焦点按钮周围虚线的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 WPF 应用程序中有多个按钮和图像,并且希望将焦点按钮和焦点图像周围的虚线都加粗.

I have multiple buttons and images in my WPF applications and would like to make the dotted line around focused buttons and focused images thicker for all of them.

我不想对每个组件都一个一个地做.相反,我正在寻找一种方法来设置虚线(虚线)的样式,该样式指示所有组件的全局焦点.

I don't want to do it one by one for each component. Instead I am looking for a way that I can set the styling of the dotted line (dashed line) which indicates what component is focused globally for all of the components.

怎么做?

推荐答案

你可以简单地定义一个针对 ButtonImage 或任何其他可聚焦控件的隐式样式,放置这个样式如 App.Resources 或一些单独的 ResourceDictionary:

You can simply define an implicit Style targeting Button or Image or any other focusable Controls, place this Style is such as App.Resources or some separate ResourceDictionary:

<Style TargetType="Button">
   <Setter Property="FocusVisualStyle">
       <Setter.Value>
           <Style>
              <Setter Property="Control.Template">
                 <Setter.Value>
                  <ControlTemplate>
                    <Rectangle StrokeThickness="2" Stroke="Black" StrokeDashArray="2"/>
                  </ControlTemplate>
                 </Setter.Value>
              </Setter>
           </Style>
       </Setter.Value>
    </Setter>
</Style>

这篇关于如何在wpf中全局更改焦点按钮周围虚线的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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