【问题标题】:WPF - Change backgroundcolor on button hoverWPF - 在按钮悬停时更改背景颜色
【发布时间】:2016-02-23 20:46:02
【问题描述】:

我尝试了许多不同的选项来更改悬停时的背景颜色,但它对我不起作用。

这是我的代码:

<Button x:Name="bAction" HorizontalAlignment="Center" Margin="0,500,0,0" VerticalAlignment="Center" Height="100" Width="1000" BorderBrush="Black" OpacityMask="White" Background="#FF5B5B5B" IsDefault="True" Click="bAction_Click">
    <TextBlock x:Name="tbAction" TextWrapping="Wrap" Text="Test" Foreground="White" IsEnabled="False" Width="990" Height="85" FontFamily="Letter Gothic Std" FontSize="21.333" FontWeight="Bold" TextDecorations="{x:Null}" TextAlignment="Center"/>
</Button>

【问题讨论】:

  • 向我们展示您的尝试。有大量的教程,甚至是关于如何做到这一点的分步视频。
  • 我会考虑使用样式。
  • 是的,一定要在样式中这样做,定义 MouseOver 触发器。

标签: wpf xaml button hover


【解决方案1】:

尝试将以下样式应用于Button

<Style x:Key="myStyle" TargetType="Button">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <ControlTemplate.Triggers>
          <Trigger Property="IsMouseOver"
                  Value="True">
            <Setter Property="Background"
                   Value="Red" />
          </Trigger>
        </ControlTemplate.Triggers>
        <ContentPresenter />
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

【讨论】:

    猜你喜欢
    • 2013-06-26
    • 2017-04-12
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    • 2018-05-15
    • 2022-12-03
    • 1970-01-01
    相关资源
    最近更新 更多