6

タッチスクリーン用の WPF での開発は初めてで、操作イベントの解釈に問題があります。私がやりたいことはかなり単純だと思います。ユーザーが UserControl のどこかをつまむと、アクションが実行されます。

だから、私が持っているコントロールで(これはSurface 2.0 / Windows Touchです):

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 がイベントを行う方法に頭を悩ませようとしています。

Edit2: より完全なコードを貼り付けます。

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>

a) はい、Semantic Zoom をエミュレートしようとしているし、b) はい、ハックな仕事をしているからです。シンプルな作業コンセプトが必要です。各ビューは基本的に CategoryView に似ています。

4

1 に答える 1

0

Andriy さん、ご協力ありがとうございます。問題は私のモニターの感度が低すぎるという単純なもののようです。操作イベントのすべてのコンテンツのイベント フックを削除し、親グリッドのフックだけを残してから、画面を 2 本の指で非常に強く押すと、イベントが発生しました。ただし、おそらくルーティングをもう少しいじる必要があります。

于 2012-04-10T19:22:33.430 に答える