将鼠标悬停在 XAML wpf 上的按钮默认突出显示颜色更改为透明? [英] Change the button default highlighted colour to transparent on mouseover XAML wpf?

查看:56
本文介绍了将鼠标悬停在 XAML 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 代码:

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

推荐答案

您需要使用按钮样式和模板.在按钮代码中添加以下代码.我想我在 stackoverflow 上找到了这段代码?不久以前.我会搜索一个链接并发布它.

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>

这篇关于将鼠标悬停在 XAML wpf 上的按钮默认突出显示颜色更改为透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆