当我在矩形上移动标签时,我希望矩形触发mouseEnter
事件,因为标签与矩形重叠,所以它不起作用。我尝试使用isHitTestVisible = false
,但后来无法移动标签。有办法做到这一点吗?
我使用了边框,因为如果我记得正确的话,这是唯一可以做到的方法。
WINDOW.RESOURCES
<Style TargetType="{x:Type Border}">
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFE6E6E6"/>
</Trigger>
</Style.Triggers>
</Style>
栅格
<Border BorderBrush="#FF000000" BorderThickness="0,0,3,3" Grid.Row="0" Grid.Column="0">
<Image Name="x0y0" Source="/Tictactoe;component/image/null-black.png"/>
</Border>
我希望我为你找到了合适的东西p
这就是您想要的吗?`
<Grid>
<Rectangle x:Name="rect" Fill="{Binding ElementName=label, Path=Background}" />
<TextBlock x:Name="label" Text="Hover over me" >
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Height" Value="20" />
<Setter Property="Width" Value="100" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightBlue" />
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
`
这就是我用DataGridRow对象实现这种效果的方法。也许这会有所帮助。
<EventTrigger RoutedEvent="DataGridRow.DragEnter">
<BeginStoryboard x:Name="DragEnterStoryboard">
<Storyboard>
<ColorAnimation
Storyboard.TargetProperty="Background.Color"
To="{StaticResource PartEntityDragEnterBackgroundColor}"
Duration="0:0:0.25"/>
<ColorAnimation
Storyboard.TargetProperty="Foreground.Color"
To="{StaticResource PartEntityDragEnterForegroundColor}"
Duration="0:0:0.25"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>