c# - WPF,我的网格的 IsMouseOver 不会改变背景颜色
问题描述
<Grid x:Name="set_bg" DockPanel.Dock="Top" Height="90" Background="Transparent" MouseDown="set_bg_MouseDown">
<Grid.Style>
<Style TargetType="{x:Type Grid}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="DarkGoldenrod"/>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Image Height="66" Opacity="0.7" Source="/Images/settings.png" RenderOptions.BitmapScalingMode="HighQuality"/>
</Grid>
我真的不知道为什么这不起作用,即使一切都应该没问题
解决方案
只需删除Background="Transparent"
. 触发器实际上正在更改背景颜色,但无法看到它何时设置为透明。