原文 WPF Multi-Touch 开发:高级触屏操作(Manipulation)

在上一篇中我们对基础触控操作有了初步了解,本篇将继续介绍触碰控制的高级操作(Manipulation),在高级操作中包含了一些特殊的触屏手势:平移、缩放、旋转,当然在WPF 中无需自行开发这些手势,只需将UI 控件的IsManipulationEnabled 属性激活,并通过以下四种事件完成各种触屏手势操作:ManipulationStarting、ManipulationStarted、ManipulationDelta、ManipulationInertiaStarting、ManipulationCompleted,下图为各事件之间的工作顺序及关系。

创建项目

新建项目在XAML 程序中写入下面代码,为<Canvas>设置ManipulationStarting、ManipulationDelta、ManipulationCompleted 事件,并在其中添加三张图片,将Image 的IsManipulationEnabled 属性均为"True",同时所有的Image 都添加了<MatrixTransform>对象,用于组合平移、缩放、旋转操作。

<Window x:Class="WpfManipulation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="500" Width="600">
<Grid>
<Canvas x:Name="touchPad" Background="Gray"
ManipulationStarting="image_ManipulationStarting"
ManipulationDelta="image_ManipulationDelta"
ManipulationCompleted="image_ManipulationCompleted">
<Image Canvas.Top="52" Canvas.Left="34" Width="200"
IsManipulationEnabled="True" Source="Images/P1.jpg">
<Image.RenderTransform>
<MatrixTransform></MatrixTransform>
</Image.RenderTransform>
</Image>
<Image Canvas.Top="75" Canvas.Left="339" Width="200"
IsManipulationEnabled="True" Source="Images/P2.jpg">
<Image.RenderTransform>
<MatrixTransform></MatrixTransform>
</Image.RenderTransform>
</Image>
<Image Canvas.Top="243" Canvas.Left="168" Width="200"
IsManipulationEnabled="True" Source="Images/P3.jpg">
<Image.RenderTransform>
<MatrixTransform></MatrixTransform>
</Image.RenderTransform>
</Image>
</Canvas>
</Grid>
</Window>

当触碰到Image 图片时,image_ManipulationStarting 事件将会自动触发,首先需要定义ManipulationContainer(即为touchPad<Canvas>),该容器的主要用于定义参考坐标,图片的任何操作均以参考坐标为准。ManipulationModes 设置可以限制哪些手势操作是程序允许的,如果没有特殊情况可设置为"All"。

private void image_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
e.ManipulationContainer = touchPad;
e.Mode = ManipulationModes.All;
}

ManipulationDelta 事件会在手势操作开始时触发,并且该手势需持续进行不得间断。通过FrameworkElement 获得接受操作的图片控件,将图片透明度降低到0.5,创建Matrix 用于控制图片MatrixTransform,利用Point 获得图片中心坐标点,通过ScaleAt、RotateAt、Translate 执行缩放、旋转、平移操作。

private void image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
FrameworkElement element = (FrameworkElement)e.Source;
element.Opacity = 0.5; Matrix matrix = ((MatrixTransform)element.RenderTransform).Matrix; var deltaManipulation = e.DeltaManipulation; Point center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
center = matrix.Transform(center); matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y); matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y); matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); ((MatrixTransform)element.RenderTransform).Matrix = matrix;
}

最后,当手指离开触摸屏即操作结束,image_ManipulationCompleted 事件触发,将图片透明度重新调整为1。

private void image_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
FrameworkElement element = (FrameworkElement)e.Source;
element.Opacity = 1;
}

程序演示

相关文章

1. WPF Multi-Touch 开发:Windows 7 安装多点触屏模拟器 
2. WPF Multi-Touch 开发:基础触屏操作(Raw Touch)

源码下载

WpfManipulation.zip

作者:李敬然(Gnie)
出处:{GnieTech} (http://www.cnblogs.com/gnielee/)
版权声明:本文的版权归作者与博客园共有。转载时须注明本文的详细链接,否则作者将保留追究其法律责任。

WPF Multi-Touch 开发:高级触屏操作(Manipulation)的更多相关文章

  1. WPF Multi-Touch 开发:基础触屏操作(Raw Touch)

    原文 WPF Multi-Touch 开发:基础触屏操作(Raw Touch) 多点触控(Multi-Touch)就是通过与触屏设备的接触达到人与应用程序交互的操作过程.例如,生活中经常使用的触屏手机 ...

  2. JS的Touch事件们,触屏时的js事件

    丫的,终于找到了JS在平板电脑上的事件!!!   iphone.ipod Touch.ipad触屏时的js事件   1.Touch事件简介   pc上的web页面鼠标会产生onmousedown.on ...

  3. iphone、ipod Touch、ipad触屏时的js事件

    1.Touch事件简介 pc上的web页面鼠 标会产生onmousedown.onmouseup.onmouseout.onmouseover.onmousemove的事件,但是在移动终端如 ipho ...

  4. html5 touch事件实现触屏页面上下滑动(二)

    五一小长假哪都没去,睡了三天,今天晕晕沉沉的投入工作了,但还是做出了一点点效果 上周用html5的touch事件把简单的滑动做出来了,实现了持续页面上下滑动的效果,参考之前 的文章及代码html5 t ...

  5. unity3d触屏操作对象运动

    using UnityEngine; using System.Collections; public class robot : MonoBehaviour { private GameObject ...

  6. 使用C#开发Metro 风格应用的路线图 -- 触屏操作

    原文 http://www.cnblogs.com/icuit/archive/2012/05/01/2478312.html win8支持多点触摸技术,而我们在屏幕上所做的各种操作,也最终转换为输入 ...

  7. Appium常用操作之「微信滑屏、触屏操作」

    坚持原创输出,点击蓝字关注我吧 作者:清菡 博客:oschina.云+社区.知乎等各大平台都有. 目录 一.滑屏操作 1.访问之后,马上就滑屏可以吗? 2.连续实现 2 次滑屏 3.代码 二.模拟触屏 ...

  8. 基于appium的模拟单点或多点触屏操作

    一.单点触控 TouchAction类:将一系列的动作放在一个链条中,然后将该链条传递给服务器,服务器接受该链条后,解析各个动作,逐个执行,TouchAction类提供了以下几种方法: 短按:pres ...

  9. window7 触屏操作相关

    一.体系概述 1.Windows Touch Input 和 Gestures消息 Windows Touch消息特性 通过在执行期间的监听和解释来使能.下面的示例展示了Windows7 上消息是怎么 ...

随机推荐

  1. Mysql的执行顺序

    参考:http://blog.csdn.net/jintao_ma/article/details/51253356 http://www.cnblogs.com/rollenholt/p/37769 ...

  2. C#关键字列表

  3. 「OC」 继承

    一.基本用法 1.设计两个类Bird.Dog 1 // Bird的声明 2 @interface Bird : NSObject 3 { 4 @public 5 int weight; 6 } 7 - ...

  4. BZOJ 1627: [Usaco2007 Dec]穿越泥地( BFS )

    BFS... --------------------------------------------------------------------------------------- #incl ...

  5. Python Extension Packages下载链接

    一.http://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载后可使用pip包管理器进行安装,在命令行中输入: pip install 安装包的路径

  6. Python之路Day15

    主要内容:WEB框架.Django基础 WEB框架 Web请求流程 -- 原始Web框架 -- 自定义Web框架 -- MVC 和 MTV # Models Views Controllers # 模 ...

  7. Nginx阅读笔记(二)之location的用法

    两个配置文件 一: server { listen 80; # # 在本机所有ip上监听80,也可以写为192.168.1.202:80,这样的话,就只监听192.168.1.202上的80口 ser ...

  8. 亲测VS2010纯静态编译QT4.8.0,实现VS2010编译调试Qt程序,QtCreator静态发布程序(图文并茂,非常详细)

    下载源代码,注意一定是源码压缩包如qt-everywhere-opensource-src-4.8.0.zip,不是Qt发布的已编译的不同版本的标准库如qt-win-opensource-4.8.0- ...

  9. poj 3295 Tautology(栈)

    题目链接:http://poj.org/problem?id=3295 思路分析:判断逻辑表达式是否为永真式问题.根据该表达式的特点,逻辑词在逻辑变量前,类似于后缀表达式求值问题. 算法中使用两个栈, ...

  10. MySQL server has gone away 解决方法

    应用程序(比如PHP)长时间的执行批量的MYSQL语句.执行一个SQL,但SQL语句过大或者语句中含有BLOB或者longblob字段.比如,图片数据的处理.都容易引起MySQL server has ...