我使用下面提到的Style来改变我按钮的样式。一切都符合预期,但我的范围是#34; IsMouseOver"只有在按钮内部写入内容之后才会出现。因此,如果我将鼠标悬停在书面内容上,它只会被触发,而不是如果我将鼠标悬停在整个按钮的任何位置。为什么这样 ?
<Style x:Key="fancyButton" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="Foreground" Value="Navy"/>
<Setter Property="Height" Value="25"/>
<Setter Property="Width" Value="150"/>
<Setter Property="Margin" Value="10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="grid">
<Border x:Name="border" CornerRadius="3" BorderBrush="Transparent" BorderThickness="2">
<ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center"></ContentPresenter>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="#d9e2f1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
答案 0 :(得分:0)
将Background
(或Border
)的Grid
设置为Transparent
,而不是默认为空
<Border x:Name="border" Background="Transparent" ...>