我是WPF用于触摸屏的新手,我在解释操作事件时遇到了麻烦.我想要做的是相当简单我相信:当用户捏住UserControl上的任何地方时,它将执行一个动作.
所以,在我的控件中(这是Surface 2.0/Windows Touch):
XAML
<Grid Background="White" IsManipulationEnabled="True"
ManipulationStarting="Grid_ManipulationStarting"
ManipulationDelta="Grid_ManipulationDelta">
<!--Some content controls-->
</Grid>
Run Code Online (Sandbox Code Playgroud)
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
}
Run Code Online (Sandbox Code Playgroud)
但是,当我在屏幕上搓手时,这些事件都不会触发.我想在这种情况下我不能理解事件的路由.我的显示器(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>
Run Code Online (Sandbox Code Playgroud)
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
只是不要评判我,因为a)是的我试图模仿语义缩放和b)是的我正在做一个hacky的工作.我只需要一个简单的工作概念.每个视图基本上类似于CategoryView.
谢谢你的帮助安德烈,但问题似乎很简单,因为我的显示器太不敏感了。在我删除了操作事件上所有内容的事件挂钩后,只留下父网格中的挂钩,然后用两根手指在屏幕上用力按下,我就触发了事件。不过,可能需要对路由进行更多的修改。
| 归档时间: |
|
| 查看次数: |
4024 次 |
| 最近记录: |