我想要一个带有居中“x”的椭圆的按钮,它会在鼠标悬停时改变它的颜色(“x”的颜色和椭圆的颜色)。
与此类似
以下得到我想要的标准外观
<Grid>
<Grid.Resources>
<Style x:Key="CloseButtonBackgroundStyle" TargetType="{x:Type Ellipse}">
<Setter Property="Width" Value="25" />
<Setter Property="Height" Value="25" />
<Setter Property="Fill" Value="#f4f4f4" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Fill" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="CloseButtonForegroundStyle" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#898989" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="16" />
<Setter Property="Padding" Value="0 0 0 4" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="#f9ebeb" />
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Ellipse Style="{StaticResource CloseButtonBackgroundStyle}" />
<TextBlock Text="x"
Style="{StaticResource CloseButtonForegroundStyle}"/>
</Grid>
问题在于使用 IsMouseOver 属性。它确实有效,但仅适用于每个控件。即,当我越过椭圆时,背景变为红色,但是当我越过文本块时,椭圆不再是鼠标悬停,因此它变回标准填充颜色。
我是否需要更改方法以使椭圆的内容成为文本块?
非常感谢