如何解决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);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。