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

不问归期 提交于 2020-06-12 07:20:37

问题


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>

回答1:


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>


来源:https://stackoverflow.com/questions/30060757/change-the-button-default-highlighted-colour-to-transparent-on-mouseover-xaml-wp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!