问题描述
我有两个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);
}