【问题标题】:Change the button default highlighted colour to transparent on mouseover XAML wpf?在鼠标悬停 XAML wpf 时将按钮默认突出显示颜色更改为透明?
【发布时间】:2015-05-05 18:38:37
【问题描述】:

我有一个透明背景的按钮。当我将鼠标移到按钮上时,按钮上明显出现浅蓝色(默认颜色)。 我想要的是即使鼠标悬停在按钮上,我的按钮背景也应该保持透明。 我怎样才能在 XAML 中做到这一点?我已经搜索过了,但找不到与我的问题相关的任何内容。几乎每个示例或演练都用于更改按钮的样式和模板。

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>

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-11
      • 1970-01-01
      • 2017-11-29
      相关资源
      最近更新 更多