C# 如何避免ScatterViewItem捕获鼠标移动事件?

C# 如何避免ScatterViewItem捕获鼠标移动事件?,c#,wpf,touch,pixelsense,C#,Wpf,Touch,Pixelsense,基本上,我有一个Surface ToolKit ScatterView,它绑定到一个图像路径列表,这些路径被模板化为ImageView。ImageView控件使用MouseUp事件,但该事件不会在鼠标启动时触发。我也用PreviewMouseUp试过了,但运气不好。为了澄清,我正在使用Surface工具包构建一个Win7 touch应用程序 Window.xaml: <s:SurfaceWindow x:Class="SurfaceApplication1.Window1" xmlns="

基本上,我有一个Surface ToolKit ScatterView,它绑定到一个图像路径列表,这些路径被模板化为ImageView。ImageView控件使用MouseUp事件,但该事件不会在鼠标启动时触发。我也用PreviewMouseUp试过了,但运气不好。为了澄清,我正在使用Surface工具包构建一个Win7 touch应用程序

Window.xaml:

<s:SurfaceWindow x:Class="SurfaceApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.microsoft.com/surface/2008"
xmlns:view="clr-namespace:SurfaceApplication1"
Title="SurfaceApplication1"
>
<Grid>
    <s:ScatterView x:Name="scatterView">
        <s:ScatterView.ItemTemplate>
            <DataTemplate>
                <view:ImageView DataContext="{Binding}" MinHeight="300" MinWidth="300"/>
            </DataTemplate>
        </s:ScatterView.ItemTemplate>
    </s:ScatterView>
</Grid>
ImageView.xaml:

<UserControl x:Class="SurfaceApplication1.ImageView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" PreviewMouseUp="Grid_MouseUp">
<Grid MouseUp="Grid_MouseUp">
    <StackPanel>
        <Image Source="{Binding}"/>
        <TextBlock Text="{Binding}" Height="20" Width="100"/>
    </StackPanel>
</Grid>


有人知道解决这个问题的方法吗?我需要在ImageView中处理MouseUp事件。谢谢。

而不是使用普通事件语法。您可以在代码隐藏中使用UIElement.AddHandler方法,并指定要接收已处理的事件

MyGrid.AddHandler(Button.ClickEvent, new RoutedEventHandler(GetHandledToo), true);

您可以在

上阅读,鼠标被捕获到ScatterViewItem,这意味着鼠标事件不会到达该项目的子项。您需要将此事件处理程序放置在ScatterViewItem本身或该项的父项上。在usercontrol的代码中,您可能可以按照
Parent.MouseUpEvent+=yourHandler

我建议在ScatterViewItem上使用ContainerActivated和ContainerDeactivated事件,而不是mouseup/down。激活事件将在第一次触按下降和最后一次触按上升时发生。在多点触摸的世界中,你必须仔细考虑当用户在任何控件上使用多个手指并一次一个地举起这些手指时会发生什么

MyGrid.AddHandler(Button.ClickEvent, new RoutedEventHandler(GetHandledToo), true);