更改默认按钮突出显示WPF [英] Changing Default Button Highlighting WPF
本文介绍了更改默认按钮突出显示WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试删除 Button
上的默认背景,但是当用户将鼠标悬停在按钮上时,将其突出显示为橙色的 Button
.到目前为止,这是我想出的.
I am trying to remove the default background on a Button
, but then highlight the Button
in orange when the user hovers over the button with their mouse. This is what I have come up with so far;
<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的文本逐渐以橙色突出显示?
However, when the user mouses over the button it is highlighted in the default blue still, instead of the orange I would like. How can I modify this so that the Button's text is gradually highlighted in orange?
推荐答案
您需要添加 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>
这篇关于更改默认按钮突出显示WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文