首页 > 解决方案 > 如何样式键提示?

问题描述

我正在尝试找到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 时,它最终看起来像这样:

KeyTip 样式测试

我想要一个纯色的背景色。不是我测试中的渐变/淡入淡出效果。我怎样才能摆脱这种默认效果?

任何帮助,将不胜感激。

以下是我查看过但没有帮助的链接:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/e0d1336c-2f95-494b-8c4e-3db8d5ab6761/how-to-style-the-keytip-pop-up-background-in-the- microsoft-ribbon?forum=officegeneral

MSDN - 键提示样式

标签: wpfxamlstyling

解决方案


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元素。


推荐阅读