Search code examples
wpfxamlstyling

How to Style KeyTips?


I am trying to find the default style for the KeyTip control; so I can just change the default values and make my own KeyTip Style. But I've had no luck at finding it.

So I've tried this:

<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>

on a normal button:

<Button 
    x:Name="buttonTEST" 
    Content="_TEST" 
    KeyTipService.KeyTip="T" 
    KeyTipService.KeyTipStyle="{StaticResource MainKeyTipStyle}" 
    Click="buttonTEST_Click" 
    />

When I run my test and press Alt it ends up looking like this:

KeyTip Style Test

I would like a solid background color. Not a gradient / fade effect as in my test. How can I get rid of this default effect?

Any help would be appreciated.

Here are links I've looked at but didn't find helpful:

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 - Key Tip Style


Solution

  • Set the Template property to a custom ControlTemplate in your KeyTipControl style:

    <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>
    

    The default one contains two Border elements.