【发布时间】:2017-10-18 09:09:10
【问题描述】:
当鼠标移过它时,我正在尝试更改 mahapp 按钮的背景颜色。问题是,如果我使用下面的代码:
<Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="50" Height="50" HorizontalContentAlignment="Left" BorderBrush="{x:Null}" Foreground="{x:Null}" Margin="50,0,0,0">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Green"/>
<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="DarkGoldenrod"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
发现 in this answer 颜色确实发生了变化,但我的按钮“忘记”成为 mahapp 按钮,即它失去了样式。
如何在不失风格的情况下改变颜色?
谢谢
【问题讨论】:
-
尝试提供基本样式:
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> -
当我修改其他属性如 Font family 声明
标签: wpf xaml mahapps.metro