【发布时间】:2017-06-19 21:01:02
【问题描述】:
我已经为一个包含边框和文本块的按钮定义了一个自定义模板,如下所示:
<Style x:Key="WindowControlButtons" BasedOn="{StaticResource WindowControlButtonsFont}" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Padding="{TemplateBinding Padding}" Height="100" Background="Yellow">
<TextBlock Text="{TemplateBinding Content}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{StaticResource FgOrangeBrush}" />
</Trigger>
</Style.Triggers>
</Style>
我试图让它在我悬停时变为橙色前景,并且它可以工作(有点)。只有当我的鼠标在实际标签下方约 5-30 像素之间时,它才会注册我的“鼠标悬停”。边框上的黄色背景是为了让我可视化按钮,但它通常是透明的。 这是该按钮的两个实例的屏幕截图:
我已经在悬停触发 IsMouseOver 触发器的大致位置添加了一个蓝色轮廓。
基本上,我想知道为什么触发器没有在大多数按钮上触发。如果有帮助,这里是按钮的声明:
<Button HorizontalAlignment="Right" Margin="10 0" Grid.Column="2" Content="X" Style="{StaticResource WindowControlButtons}" />
<Button HorizontalAlignment="Right" Margin="35 0" Grid.Column="2" Content="_" Style="{StaticResource WindowControlButtons}" />
非常感谢!
【问题讨论】: