我正在尝试删除Button
上的默认背景,但是当用户用鼠标悬停在按钮上时,突出显示橙色的Button
。这是我到目前为止所提出的;
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="FontSize" Value="20" />
<Setter Property="Margin" Value="5" />
<Setter Property="MaxHeight" Value="30" />
<Setter Property="Width" Value="150" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Cursor" Value="Hand" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Orange"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
然而,当用户将鼠标悬停在按钮上时,它会以默认的蓝色突出显示,而不是我想要的橙色。如何修改此按钮以使Button的文本逐渐以橙色突出显示?
答案 0 :(得分:2)
您需要添加ControlTemplate.Trigger
:
<Style TargetType="{x:Type Button}">
<Setter Property="FontSize" Value="20" />
<Setter Property="Margin" Value="5" />
<Setter Property="MaxHeight" Value="30" />
<Setter Property="Width" Value="150" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="Orange"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>