wpf - 如何样式键提示?
问题描述
我正在尝试找到KeyTip
控件的默认样式;所以我可以更改默认值并制作自己的KeyTip
样式。但我没有运气找到它。
所以我试过这个:
<Style x:Key="MainKeyTipStyle" TargetType="KeyTipControl" >
<Setter Property="Background" Value="Green"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Effect" Value="{x:Null}"/>
</Style>
在普通按钮上:
<Button
x:Name="buttonTEST"
Content="_TEST"
KeyTipService.KeyTip="T"
KeyTipService.KeyTipStyle="{StaticResource MainKeyTipStyle}"
Click="buttonTEST_Click"
/>
当我运行测试并按 Alt 时,它最终看起来像这样:
我想要一个纯色的背景色。不是我测试中的渐变/淡入淡出效果。我怎样才能摆脱这种默认效果?
任何帮助,将不胜感激。
以下是我查看过但没有帮助的链接:
解决方案
将Template
属性设置为ControlTemplate
您的KeyTipControl
样式中的自定义:
<Style x:Key="MainKeyTipStyle" TargetType="KeyTipControl" >
<Setter Property="Background" Value="Green"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Effect" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="KeyTipControl">
<Border Name="OuterBorder"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<TextBlock Text="{TemplateBinding Text}" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
默认包含两个Border
元素。
推荐阅读
- css - Gantry 5 网格系统与 Bootstrap 4 相同
- postgresql - 什么是postgresql查询来查找没有时区的时间戳
- ruby-on-rails - “有没有办法在 ActiveModel::Type::Value 中引发错误?”
- android - 使用 Kotlin 从 RecyclerAdapter 更改 MainActvity 中的 TextView
- php - 如何在PHP中显示2个日期之间的所有天数
- php - PHP下载的文件在firefox拼图中是0字节
- angular - 如何在构建期间添加模块 - Angular
- python - 如何用python中的模板函数来表达生成器函数
- node.js - 无法在 MongoDB 中加入两个集合
- c++ - 在 va_arg 上访问违规