简体   繁体   中英

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

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM