我想要一个带中心“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属性。它确实有效,但仅适用于每个控件。即当我在椭圆上时,背景变成红色,但是当我越过文本块时,椭圆不再是鼠标悬停,因此它回到标准填充颜色。
我是否需要改变我的方法,以便椭圆的内容是文本块?
非常感谢
非常好,这正是我一直在寻找的。谢谢。 – obaylis 2011-12-19 14:00:23
很高兴这一切工作! – 2011-12-19 15:43:43