C# How to make UWP XAML button not show border on hover

Viewed 619

Here is my button:

    <Button
        x:Name="buttonClear"
        Width="74"
        Height="52"
        Margin="3,175,0,0"
        Padding="8,1,8,5"
        HorizontalAlignment="Left"
        VerticalAlignment="Top"
        Content="C"
        FontSize="24"
        FontWeight="Normal"
        FocusVisualPrimaryBrush="Transparent"
        FocusVisualSecondaryThickness="0"
        Style="{ThemeResource ButtonRevealStyle}"
        Click="ButtonClear_Click" />

As you can see, I have added:

FocusVisualPrimaryBrush="Transparent"
FocusVisualSecondaryThickness="0"

I thought it would get rid of the gray border that shows when you hover your mouse pointer on the button. But it didn't work.

I also tried adding the following to App.xaml:

<Application.Resources>
    <SolidColorBrush x:Key="ButtonBackgroundPointerOver">Transparent</SolidColorBrush>
</Application.Resources>

Still no result. Do I have to reference the key somewhere else?

2 Answers

The easiest solution is to just hide the border with BorderThickness="0"

Alternatively you can edit the full style of the button as suggested by visc.

You need to modify the full style of the Button. The full Button style has VisualState definition for hover. Just modify or remove its storyboard.

Look at this link and you will find the full default button style definition. https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/button-styles-and-templates

I personally create a resource dictionary file I import to all my pages and when I define new buttons I set the BasedOn to my modified button style in the resource dictionary.

Related