【发布时间】:2017-09-06 19:04:48
【问题描述】:
UWP:如何删除 ToggleButton 的鼠标悬停和鼠标按下背景?
XAML:
(PS:这适用于Button!)
<Style TargetType="ToggleButton">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Grid x:Name="RootGrid" Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
</VisualState>
<VisualState x:Name="PointerOver">
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter
x:Name="ContentPresenter"
BorderBrush="Transparent"
BorderThickness="{TemplateBinding BorderThickness}"
Content="{TemplateBinding Content}"
ContentTransitions="{TemplateBinding ContentTransitions}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
AutomationProperties.AccessibilityView="Raw"
Foreground="White"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
结果(注意周围的黑色方块和较暗的背景):
同一个按钮的另一张图片,但后来被检查了,也许更好地看看它看起来有多可怕。
【问题讨论】:
-
我强烈建议您尝试使用
ToggleButton的样式来控制其外观,而不是像这样硬编码的图像。