Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the button default highlighted colour to transparent on mouseover XAML wpf?

Tags:

c#

wpf

xaml

I have a button with transparent background. When i move mouse over on the button, a light blue colour appears on the button(Default Colour) obviously. what i want is that my button background should remain transparent even when the mouse is over the button. How can i do it in XAML? i have searched it but couldn't find anything related to my problem. Almost Every Example or walkthrough is for changing styles and templates of the button.

XAML Code:

   <Button HorizontalAlignment="Left" Margin="130,92,0,0" VerticalAlignment="Top" Width="223" Height="95.96" Background="{x:Null}" BorderThickness="0">
        <Image Height="95.96" Source="Beam-Bridge-3D-Model.png" Stretch="Fill" Width="182.829"/>
    </Button>
like image 903
Vanadium90 Avatar asked Oct 21 '25 20:10

Vanadium90


1 Answers

You need to use a button style and template. Add the following code inside your button code. I think I found this code on stackoverflow? a while ago. I'll search for a link and post it as well.

            <Button.Style>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Border Background="{TemplateBinding Background}">
                                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="Transparent"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
like image 99
Cristian Avatar answered Oct 23 '25 10:10

Cristian