WPF如何引发两个相互重叠的UIElement上的鼠标事件

问题描述

我有两个UIElement。在ViewBox和Canvas中覆盖的图像。在两者后面的代码中都注册了MoseMove事件。 当前仅在顶部的元素上引发该事件。

有什么方法可以在两个UIElement上引发MouseMove吗?

XAML:

PCollection<Long>

隐藏代码

<Window x:Class="WpfApp2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp2"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid ClipToBounds="True">
        <ViewBox Name="border" StretchDirection="Both" Stretch="Uniform" Panel.ZIndex="0" >
            <Grid>
                <Image Name="image"  Panel.ZIndex="1"  >
                    <Image.source>
                        <BitmapImage UriSource="d:\test.png"/>
                    </Image.source>
                </Image>
            </Grid>
        </ViewBox>
        <Canvas Name="canvas" Panel.ZIndex="2" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
    </Grid>
</Window>

解决方法

您可以尝试:)

private void Canvas_PreviewMouseMove(object sender,MouseEventArgs e)
{
     border.RaiseEvent(e);
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...