WPF Multi-Touch 开发:高级触屏操作(Manipulation)
原文 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)
源码下载
出处:{GnieTech} (http://www.cnblogs.com/gnielee/)
版权声明:本文的版权归作者与博客园共有。转载时须注明本文的详细链接,否则作者将保留追究其法律责任。
WPF Multi-Touch 开发:高级触屏操作(Manipulation)的更多相关文章
- WPF Multi-Touch 开发:基础触屏操作(Raw Touch)
原文 WPF Multi-Touch 开发:基础触屏操作(Raw Touch) 多点触控(Multi-Touch)就是通过与触屏设备的接触达到人与应用程序交互的操作过程.例如,生活中经常使用的触屏手机 ...
- JS的Touch事件们,触屏时的js事件
丫的,终于找到了JS在平板电脑上的事件!!! iphone.ipod Touch.ipad触屏时的js事件 1.Touch事件简介 pc上的web页面鼠标会产生onmousedown.on ...
- iphone、ipod Touch、ipad触屏时的js事件
1.Touch事件简介 pc上的web页面鼠 标会产生onmousedown.onmouseup.onmouseout.onmouseover.onmousemove的事件,但是在移动终端如 ipho ...
- html5 touch事件实现触屏页面上下滑动(二)
五一小长假哪都没去,睡了三天,今天晕晕沉沉的投入工作了,但还是做出了一点点效果 上周用html5的touch事件把简单的滑动做出来了,实现了持续页面上下滑动的效果,参考之前 的文章及代码html5 t ...
- unity3d触屏操作对象运动
using UnityEngine; using System.Collections; public class robot : MonoBehaviour { private GameObject ...
- 使用C#开发Metro 风格应用的路线图 -- 触屏操作
原文 http://www.cnblogs.com/icuit/archive/2012/05/01/2478312.html win8支持多点触摸技术,而我们在屏幕上所做的各种操作,也最终转换为输入 ...
- Appium常用操作之「微信滑屏、触屏操作」
坚持原创输出,点击蓝字关注我吧 作者:清菡 博客:oschina.云+社区.知乎等各大平台都有. 目录 一.滑屏操作 1.访问之后,马上就滑屏可以吗? 2.连续实现 2 次滑屏 3.代码 二.模拟触屏 ...
- 基于appium的模拟单点或多点触屏操作
一.单点触控 TouchAction类:将一系列的动作放在一个链条中,然后将该链条传递给服务器,服务器接受该链条后,解析各个动作,逐个执行,TouchAction类提供了以下几种方法: 短按:pres ...
- window7 触屏操作相关
一.体系概述 1.Windows Touch Input 和 Gestures消息 Windows Touch消息特性 通过在执行期间的监听和解释来使能.下面的示例展示了Windows7 上消息是怎么 ...
随机推荐
- C-C Radar Installation 解题报告
C-C Radar Installation 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#pr ...
- ThinkPHP第十天(_initialize方法,SESSION销毁,分组配置,include文件引入,JOIN用法)
1.Action类中的_initialize()函数,先于任何自定义操作函数运行,可认为是控制器的前置操作.可用于检测用户是否登录等检测. 如果多个模块(Action)需要相同_initialize( ...
- LinkList Operation
链表典型数据结构: #define ElemType int typedef struct LinkNode{ ElemType value; struct LinkNode* next; }; 相比 ...
- Python (九) 协程以及数据库操作
本节内容 Gevent协程 Select\Poll\Epoll异步IO与事件驱动 Python连接Mysql数据库操做 Paramiko SSH 协程 协程,又称微线程,纤程.英文名Coroutine ...
- 【转】页面尺寸不一样的PDF页面调整方法
本文综合参考:http://www.360doc.com/content/10/1114/22/2961363_69395272.shtml http://blog.sina.com.cn/s/blo ...
- spring mvc实现ajax 分页
使用到的技术: ·spring 3 mvc ·json ·jquery ·java ·mysql 首先,要了解如何在spring mvc中使用json. 以下主要从Dao和View及Controlle ...
- C的memset,memcpy,strcpy 的区别 及memset memcpy memmove源码
extern void *memcpy(void *dest,void *src,unsigned int count);#include <string.h> 功能:由src所指内存 ...
- cocos2d-x游戏开发系列教程-超级玛丽03-main函数
代码下载链接 http://download.csdn.net/detail/yincheng01/6864893 解压密码:c.itcast.cn main函数内容 #include "m ...
- 【图文】雪佛兰Suburban 美国特工标准座驾_新闻中心_易车网
[图文]雪佛兰Suburban 美国特工标准座驾_新闻中心_易车网 雪佛兰Suburban 美国特工标准座驾
- Lync 2010升级到Lync 2013POC计划-过程!
最近在协助一家客户做升级项目调研,目前处在POC过程中,根据他们的需求我们将整个POC过程用Project 进行了下整理,了解整个项目中可能存在的风险和相应的计划过程,根据相应的计划我们能够将相应过程 ...