WPF:触发与另一个UIElement重叠的UIElement上的mouseenter

时间:2016-03-27 22:02:21

标签: c# wpf mouseevent uielement

当我在Rectangle上移动标签时,我希望矩形触发mouseEnter事件,它不起作用,因为Label重叠了Rectangle。我尝试了isHitTestVisible = false,但后来我无法移动标签。有没有办法做到这一点?

3 个答案:

答案 0 :(得分:0)

我使用了边框,因为如果我没记错的话,这是唯一的方法。

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>

GRID

<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

答案 1 :(得分:0)

这是你要找的吗? `

Input

`

答案 2 :(得分:0)

这就是我使用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>