【发布时间】:2016-02-23 09:50:09
【问题描述】:
我有一个Button,我想要一个橙色Background 和一个白色Foreground。当我将鼠标悬停在Button 上时,我希望它显示在DarkOrange 中。这是我目前使用的Style。
<Style TargetType="{x:Type Button}">
<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="Foreground" Value="White"/>
<Setter Property="Background" Value="DarkOrange"/>
</Trigger>
</Style.Triggers>
</Style>
如果我不修改我的Button 的原始Background 颜色,则此样式可以正常工作。例如;
<Button Grid.Row="2" Content="SIGN IN" />
没有问题。但是,当我想更改Button 的默认Background 时,即
<Button Grid.Row="2" Content="SIGN IN" Background="Orange"/>
样式不起作用。我认为这是因为我现在覆盖了 IsMouseOver 试图更改的 Background 属性。
有没有一种方法可以同时实现修改后的默认Background 和IsMouseOver 效果?我也试过设置<Border Background="Orange">,但还是没有效果。
【问题讨论】: