2012-04-09 47 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中的鉤子,然後用兩個手指在屏幕上非常難以按下,我就會觸發事件。雖然可能需要更多的路由。