2012-04-09 56 views
5

我是新开发的WPF触摸屏,我在解释操作事件时遇到了麻烦。我想做的事情非常简单,我相信:当用户捏住UserControl的任何地方时,它会执行一个动作。操作事件没有触发

所以,在我的控制(这是表面2.0/Windows触控):

XAML

<Grid Background="White" IsManipulationEnabled="True" 
ManipulationStarting="Grid_ManipulationStarting" 
ManipulationDelta="Grid_ManipulationDelta"> 
    <!--Some content controls--> 
</Grid> 

C#

private void Grid_ManipulationStarting(object sender, ManipulationStartingEventArgs e) 
{ 
    e.ManipulationContainer = this; 
} 

private void Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) 
{ 
    //do the thing... you know, that thing you do 
} 

然而,这些都不当我在屏幕上揉搓双手时,事件会发生。在这种情况下,我认为我不能理解事件的路线。我的显示器(3M MicroTouch PX)在理解触摸事件或内置操作(如ScatterViewItems)方面没有任何问题。

编辑:我从网格内删除控件,现在他们开火,所以我猜操作正在被内容拦截。对不起,应该更清楚控制的内容,因为它们看起来似乎是问题。

具体而言,我认为它与我有一个SurfaceListBox里面的事实有关。我会想象SurfaceListBox拦截操作。有什么办法可以告诉它离开?我仍然试图围绕WPF执行事件的方式进行讨论。

编辑2:要粘贴一些更完整的代码。

SEMANTICPANEL.XAML FULL

<UserControl x:Class="SemanticZoom.SemanticPanel" 
     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" 
     xmlns:local="clr-namespace:SemanticZoom" 
     xmlns:views="clr-namespace:SemanticZoom.Views" 
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="300"> 
<UserControl.Resources> 
</UserControl.Resources> 
<Grid Background="White" IsManipulationEnabled="True" ManipulationStarting="Grid_ManipulationStarting" ManipulationDelta="Grid_ManipulationDelta"> 
    <views:CategoryView x:Name="CategoryView"/> 
    <views:ShelfView x:Name="ShelfView" Visibility="Hidden" /> 
    <views:BookView x:Name="BookView" Visibility="Hidden" /> 
</Grid> 

SEMANTICPANEL.CS FULL

public partial class SemanticPanel : UserControl 
{ 
    public SemanticPanel() 
    { 
     InitializeComponent(); 
     CategoryView.CategorySelected += new EventHandler(CategoryView_CategorySelected); 
     ShelfView.BookSelected += new EventHandler(ShelfView_BookSelected); 
     ShelfView.ZoomOut += new EventHandler(View_ZoomOut); 
    } 

    void View_ZoomOut(object sender, EventArgs e) 
    { 
     if (sender == ShelfView) 
     { 
      ShelfView.Visibility = System.Windows.Visibility.Hidden; 
      CategoryView.Visibility = System.Windows.Visibility.Visible; 
     } 
     else if (sender == BookView) 
     { 
      BookView.Visibility = System.Windows.Visibility.Hidden; 
      ShelfView.Visibility = System.Windows.Visibility.Visible; 
     } 
    } 

    void ShelfView_BookSelected(object sender, EventArgs e) 
    { 
     BookView.Books = ShelfView.BookList; 
     ShelfView.Visibility = System.Windows.Visibility.Hidden; 
     BookView.Visibility = System.Windows.Visibility.Visible; 
    } 

    void CategoryView_CategorySelected(object sender, EventArgs e) 
    { 
     ShelfView.Category = CategoryView.ActiveCategory; 
     ShelfView.Visibility = System.Windows.Visibility.Visible; 
     CategoryView.Visibility = System.Windows.Visibility.Hidden; 
     ShelfView.RefreshBooks(); 
    } 

    private void Grid_ManipulationStarting(object sender, ManipulationStartingEventArgs e) 
    { 
     //e.ManipulationContainer = this; 
    } 

    private void Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) 
    { 
     if (e.DeltaManipulation.Scale.X < 0) 
     { 
      if (ShelfView.Visibility == System.Windows.Visibility.Visible) 
      { 
       ShelfView.Visibility = System.Windows.Visibility.Hidden; 
       CategoryView.Visibility = System.Windows.Visibility.Visible; 
      } 
      else if (BookView.Visibility == System.Windows.Visibility.Visible) 
      { 
       BookView.Visibility = System.Windows.Visibility.Hidden; 
       ShelfView.Visibility = System.Windows.Visibility.Visible; 
      } 
     } 
    } 

CATEGORYVIEW.XAML

<UserControl x:Class="SemanticZoom.Views.CategoryView" 
     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" 
     xmlns:s="http://schemas.microsoft.com/surface/2008" 
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="300"> 
<UserControl.Resources> 
    <!--CATEGORY TEMPLATE--> 
    <DataTemplate x:Name="CategoryTemplate" x:Key="CategoryTemplate"> 
     <s:SurfaceButton Background="Gray" Click="CategoryClicked" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="200" Width="300"> 
      <TextBlock Text="{Binding Name}" TextWrapping="Wrap" Foreground="White" FontSize="20" FontWeight="Bold" /> 
     </s:SurfaceButton> 
    </DataTemplate> 
    <!--CATEGORY STYLE--> 
    <Style TargetType="{x:Type s:SurfaceListBoxItem}"> 
     <Setter Property="Width" Value="300"/> 
     <Setter Property="Height" Value="200"/> 
    </Style> 
</UserControl.Resources> 
<Grid> 
    <s:SurfaceListBox x:Name="CategoryList" ItemTemplate="{StaticResource CategoryTemplate}"> 
     <s:SurfaceListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <WrapPanel IsItemsHost="True" 
          Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}, Mode=FindAncestor}}"/> 
      </ItemsPanelTemplate> 
     </s:SurfaceListBox.ItemsPanel> 
    </s:SurfaceListBox> 
</Grid> 

只是不要对我做出判断,因为一)是的,我试图仿效语义变焦和b)是我在做它的哈克工作。我只需要一个简单的工作概念。每个视图基本上与CategoryView类似。

+0

为什么要更改e.ManipulationContainer? – 2012-04-09 21:01:35

+0

你也确定你在我们的网格区域触摸屏幕吗?它够大吗? – 2012-04-09 21:04:19

+0

@AndriyBuday:我真的不知道,这是我看过的一个样本的一部分。因为它从来没有被调用过,所以没有什么区别,但是我会评论它,直到我解决问题。网格现在是全屏显示,并且背景颜色证实了这一点。所以我至少不会错过它。 – 2012-04-09 21:15:51

回答

0

感谢您的帮助Andriy,但问题似乎很简单,因为我的显示器太麻烦了。当我删除操作事件上的所有内容的事件钩子后,只留下父Grid中的钩子,然后用两个手指在屏幕上非常难以按下,我就会触发事件。虽然可能需要更多的路由。