本文介绍了触摸/操纵/惯性事件不会在代码中引发,而是映射到鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

触摸显示器HP L5006tm
Elo TouchSystems多点触控驱动程序1.4
Windows 7专业版
Visual Studio 2010
WPF4/C#

Touch monitor HP L5006tm
Elo TouchSystems Multi-touch Driver 1.4
Windows 7 Professional Edition
Visual Studio 2010
WPF4/C#

尽管我的触摸屏硬件仅支持单指触摸,但我发现跨接,平移和惯性手势都可以正常工作,因为我可以清楚地看到它们在桌面,MSPaint,IE9,Silverlight网站甚至在Visual Studio中的运行情况用户界面.

Although my touch screen hardware only supports single finger touch, I find that spanning, translation and inertia gestures are working ok as I clearly see them in action on my desktop, in MSPaint, IE9, Silverlight sites and even in visual studio UI.

但是在我的代码中,触摸/操纵/惯性事件只是不触发.例如,以下直接代码中的TouchUp事件不会触发,而是引发为MouseUp:

But in my code, touch/manipulation/inertia events just simply don't fire. For example, TouchUp event in the following straight piece of code does not fire and instead is raised as MouseUp:

< Window x:Class =" WpfApp2.MainWindow"
       xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation " ;
       xmlns:x =" http://schemas.microsoft.com/winfx/2006/xaml "
      标题="MainWindow".高度="300".宽度="300">
    < StackPanel>
           <标签名称="label1"保证金="20".背景=黄色".
                MouseUp ="label1_MouseUp";
                TouchUp ="label1_TouchUp"
                >触摸我或点击我查看消息框</标签>
    </StackPanel>
</Window>

<Window x:Class="WpfApp2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="300" Width="300">
    <StackPanel>
            <Label Name="label1" Margin="20" Background="Yellow"
                   MouseUp="label1_MouseUp"
                   TouchUp="label1_TouchUp"
                   >Touch me or click me to see message box</Label>
    </StackPanel>
</Window>

如果有人可以告诉我我在这里想念什么,我将非常有义务?

I'll be much obliged if any anybody can tell me what am I missing here ?

预先感谢

Mansoor

推荐答案

  

  

如果您只想专门处理触摸事件,则需要更改窗口 SurfaceWindow .

If you want to specifically handle only Touch events, you need to change your Window to a SurfaceWindow.

然后将启用其中的所有控件.

Then all the controls within will be touch enabled.

  

   

1. 下载Microsoft Surface API

1. Download Microsoft Surface API

2.包括对 Microsoft.Surface.Presentation

3.尝试以下代码:

<s:SurfaceWindow
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Class="WpfApplication10.MainWindow" Title="MainWindow"
    xmlns:local="clr-namespace:WpfApplication10" Height="300" Width="400"
    xmlns:s="http://schemas.microsoft.com/surface/2008">

    <Label Content="Try me" TouchDown="element_TouchDown" Height="255" HorizontalAlignment="Left" Name="canvas1" VerticalAlignment="Top" Width="235" Background="#FFCE4545"  />

</s:SurfaceWindow>


using System.Windows;
using Microsoft.Surface.Presentation.Controls;

namespace WpfApplication10
{
    public partial class MainWindow : SurfaceWindow
	{
        public MainWindow()
		{
			this.InitializeComponent();
		}

        private void element_TouchDown(object sender, System.Windows.Input.TouchEventArgs e)
        {
            MessageBox.Show("here");
        }
    }
}

 

现在会触发通知触摸事件.

 

Notice Touch events now fire.

然后更改回普通窗口,事件再次失败.

Then change back to a normal Window, events fail again.

此处 a> .

Read all about touch here.

  

   

我的理解是,您必须启用触摸功能.有一个功能叫做 RegisterTouchWindow ,可能还有一些方法可以使用 TouchTarget ,但使用Surface API要简单得多.此外,如果您正在开发Touch应用程序,那么您将明智地使用所有iPhone风格,在Surface API中启用触摸功能的控件,从而省去了很多麻烦.它 甚至还有一个触摸模拟器,您可以在普通台式机上测试您的应用程序.

My understanding is that you have to enable Touch. There is a function calledRegisterTouchWindow, and probably some way to code this up usingTouchTarget, but it's far simpler to use the Surface API. Besides, if you're developing a Touch application, you'd be WISE to use all the iPhone style, touch enabled controls in the Surface API and save yourself a whole lot of headache. It even has a touch emulator that you can test your applications on a normal desktop.

此致,
皮特

Regards,
Pete


这篇关于触摸/操纵/惯性事件不会在代码中引发,而是映射到鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!