windows8 开发教程 教你制作 多点触控Helper可将任意容器内任意对象进行多点缩放...
http://blog.csdn.net/wangrenzhu2011/article/details/7732907 (转)
实现方法:
对Manipulation进行抽象化 使不同容器可共用多点缩放事件,
C# 代码如下:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Windows.Foundation;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Media.Animation;
- namespace MetroTimeline
- {
- public class MetroManipulationHelper
- {
- /// <summary>
- /// 发生碰撞时的操作方法库
- /// </summary>
- public static Dictionary<Predicate<string>, Action<ManipulationDeltaRoutedEventArgs>>
- BoundaryFeedbackDict = new Dictionary<Predicate<string>, Action<ManipulationDeltaRoutedEventArgs>>();
- /// <summary>
- /// 多点触控开始后方法库
- /// </summary>
- public static Dictionary<Predicate<string>, Action<ManipulationStartedRoutedEventArgs>>
- ManipulationStartedDict = new Dictionary<Predicate<string>, Action<ManipulationStartedRoutedEventArgs>>();
- /// <summary>
- /// 多点触控完成后方法库
- /// </summary>
- public static Dictionary<Predicate<string>, Action<ManipulationCompletedRoutedEventArgs>>
- ManipulationCompletedDict = new Dictionary<Predicate<string>, Action<ManipulationCompletedRoutedEventArgs>>();
- /// <summary>
- /// 需要执行的方法的关键字
- /// </summary>
- private static string methodTag;
- public static string MethodTag
- {
- get { return MetroManipulationHelper.methodTag; }
- set { MetroManipulationHelper.methodTag = value; }
- }
- /// <summary>
- /// 将容器变为多点操控容器
- /// </summary>
- /// <param name="container"></param>
- /// <param name="mode"></param>
- /// <param name="trans"></param>
- /// <param name="scale"></param>
- /// <param name="rotation"></param>
- /// <param name="containerRect">容器相对父级菜单位置</param>
- public static void InitManipulation(FrameworkElement container, ManipulationModes mode,
- double trans, double scale, double rotation, Rect containerRect)
- {
- BoundaryFeedbackDict.Add(s => s.Equals("default"), e =>
- {
- var element = e.OriginalSource as FrameworkElement;
- var con = e.Container as Panel;
- var elementBounds = element.RenderTransform.TransformBounds(new Rect(e.Position, element.RenderSize));
- Point fp = new Point((elementBounds.Left + elementBounds.Right) / 2, (elementBounds.Top + elementBounds.Bottom) / 2);
- if (fp.X < containerRect.Left ||
- fp.X > containerRect.Right ||
- fp.Y < containerRect.Top ||
- fp.Y > containerRect.Bottom)
- {
- e.Complete();
- }
- });
- container.ManipulationStarting += ElementManipulationEventHandler(container, mode);
- container.ManipulationDelta += ElementManipulationDeltaEventHandler();
- container.ManipulationStarted += ElementManipulationStartedEventHandler();
- container.ManipulationCompleted += ElementManipulationCompletedEventHandler();
- container.ManipulationInertiaStarting += ElementManipulationInertiaStartingEventHandler(trans, scale, rotation);
- foreach (var item in (container as Panel).Children)
- {
- if (item.ManipulationMode == ManipulationModes.All)
- {
- var group = new TransformGroup();
- group.Children.Add(new TranslateTransform());
- group.Children.Add(new ScaleTransform());
- group.Children.Add(new RotateTransform());
- item.RenderTransform = group;
- }
- }
- }
- #region 多点手势方法
- #region 多点触控手势开始操作
- public static ManipulationStartingEventHandler ElementManipulationEventHandler(FrameworkElement element, ManipulationModes mode)
- {
- return (sender, e) =>
- {
- e.Container = element;
- e.Mode = mode;
- };
- }
- #endregion
- #region 多点触控手势过程中操作
- public static ManipulationDeltaEventHandler ElementManipulationDeltaEventHandler()
- {
- return ((sender, e) =>
- {
- var element = e.OriginalSource as FrameworkElement;
- var center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
- var tt = (element.RenderTransform as TransformGroup).Children[0] as TranslateTransform;
- tt.X += e.Delta.Translation.X;
- tt.Y += e.Delta.Translation.Y;
- var st = (element.RenderTransform as TransformGroup).Children[1] as ScaleTransform;
- st.CenterX = center.X;
- st.CenterY = center.Y;
- st.ScaleX *= e.Delta.Scale;
- st.ScaleY *= e.Delta.Scale;
- var rt = (element.RenderTransform as TransformGroup).Children[2] as RotateTransform;
- rt.CenterX = center.X;
- rt.CenterY = center.Y;
- rt.Angle += e.Delta.Rotation;
- if (e.IsInertial)
- if (null != BoundaryFeedbackDict)
- foreach (var item in BoundaryFeedbackDict)
- {
- if (null != MethodTag)
- if (item.Key(MethodTag)) item.Value(e);
- };
- });
- }
- #endregion
- #region 多点手势开始后
- private static ManipulationStartedEventHandler ElementManipulationStartedEventHandler()
- {
- return (sender, e) =>
- {
- if (null != ManipulationStartedDict)
- foreach (var item in ManipulationStartedDict)
- {
- if (null != MethodTag)
- if (item.Key(MethodTag)) item.Value(e);
- };
- };
- }
- #endregion
- #region 多点手势完成
- private static ManipulationCompletedEventHandler ElementManipulationCompletedEventHandler()
- {
- return (sender, e) =>
- {
- if (null != ManipulationCompletedDict)
- foreach (var item in ManipulationCompletedDict)
- {
- if (null != MethodTag)
- if (item.Key(MethodTag)) item.Value(e);
- };
- };
- }
- #endregion
- #region 多点手势惯性开始
- /// <summary>
- ///
- /// </summary>
- /// <param name="trans">10</param>
- /// <param name="scale">0.1</param>
- /// <param name="rotation">540</param>
- /// <returns></returns>
- private static ManipulationInertiaStartingEventHandler ElementManipulationInertiaStartingEventHandler(double trans, double scale, double rotation)
- {
- return (sender, e) =>
- {
- e.TranslationBehavior.DesiredDeceleration = trans * 96.0 / (1000.0 * 1000.0);
- e.ExpansionBehavior.DesiredDeceleration = scale * 96 / 1000.0 * 1000.0;
- e.RotationBehavior.DesiredDeceleration = rotation / (1000.0 * 1000.0);
- };
- }
- #endregion
- #endregion
- }
- }
xaml :
- <Page
- x:Class="MetroTimeline.MainPage"
- IsTabStop="false"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:MetroTimeline"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d">
- <Canvas Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
- Width="1080" Height="500"
- x:Name="cvsContent" Tag="default">
- <TextBlock Canvas.Left="573" TextWrapping="Wrap" Text="TextBlock" x:Name="tbInfo" ManipulationMode="All" Margin="219,597,171,10"/>
- <Image Source="Assets/PicWallLoading.jpg" ManipulationMode="All" Height="202" Canvas.Left="75" Canvas.Top="209" Width="153"/>
- <Image Source="Assets/PicWallLoading.jpg" ManipulationMode="All" Height="202" Canvas.Left="333" Canvas.Top="83" Width="153"/>
- </Canvas>
- </Page>
使用方式:
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- using Windows.UI.Xaml.Data;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Navigation;
- // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
- namespace MetroTimeline
- {
- /// <summary>
- /// An empty page that can be used on its own or navigated to within a Frame.
- /// </summary>
- public sealed partial class MainPage : Page
- {
- public MainPage()
- {
- this.InitializeComponent();
- var conRect = new Rect(Canvas.GetLeft(cvsContent), Canvas.GetTop(cvsContent),
- cvsContent.Width, cvsContent.Height);
- MetroManipulationHelper.InitManipulation(cvsContent, ManipulationModes.All, 5, 0.5, 360, conRect);
- MetroManipulationHelper.MethodTag = cvsContent.Tag.ToString();
- }
- /// <summary>
- /// Invoked when this page is about to be displayed in a Frame.
- /// </summary>
- /// <param name="e">Event data that describes how this page was reached. The Parameter
- /// property is typically used to configure the page.</param>
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- }
- }
- }
conRect 为当前需要操作的容器 相对他父级容器的大小以及位置,用于判断多点元素的活动范围,
如果范围是全屏的话 则无需传该参数,进行相应修改即可
最后是效果图:
demo 下载地址:http://download.csdn.net/detail/wangrenzhu2011/4420853
转载于:https://www.cnblogs.com/CharlesGrant/p/3639228.html
windows8 开发教程 教你制作 多点触控Helper可将任意容器内任意对象进行多点缩放...相关推荐
- windows8 开发教程 教你制作 多点触控Helper可将任意容器内任意对象进行多点缩放...
实现方法: 对Manipulation进行抽象化 使不同容器可共用多点缩放事件, C# 代码如下: using System; using System.Collections.Generic; us ...
- 嵌入式Linux应用程序开发-(10)i.MX6UL基于嵌入式QT实现电容屏多点触控
i.MX6UL基于嵌入式QT实现电容屏多点触控 基于i.MX6UL平台,使用嵌入式QT实现电容屏的多点触控,前提是开发板的电容触摸屏驱动已经支持多点触控,并且驱动程序能通过事件方式向应用程序上报触控数 ...
- 多点触控与多鼠标支持
多点触控与多鼠标支持 最进将工作流平台进行了升级,除了用WF4重新构建了后台,最大的改变就是全部图形化了用户界面 原计划在用户界面中全面启用多点触控技术,但发现多点触控的效果没有想象中的那么绚. 下面 ...
- android 单点跟长按的区别,单点触控和多点触控区别是什么?原理分析
描述 导语:触屏手机.平板电脑等新型的智能设备的崛起,除了因为像安卓和ios这样的智能系统诞生的原因外,不可或缺的一个条件就是触摸屏幕的更新换代和多点触控技术的出现.下面我们就来介绍单点触控和多点触控 ...
- Android自定义控件ImageViwe(四)——多点触控实现图片的自由移动
效果图: 功能 : 可以随手指进行自由移动图片 按照适当的比例设置图片的显示 首先将图片按照适当的比例显示在自定义控件中(当图片的宽度或者高度大于控件的宽度或者高度的时候,会对图片进行适当的缩放,当图 ...
- 基于Visual C++ 2010开发Windows7应用 开发多点触控MFC应用程序
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 当下计算 ...
- Android开发实例之多点触控程序
智能终端设备的多点触控操作为我们带来了种种炫酷体验,这也使得很多Android开发者都对多点触控程序的开发感兴趣.实际上多点触控程序的实现并不是那么遥不可及,而是比较容易.本文就主要通过一个实例具体讲 ...
- PS教程 教你制作古老的石头
PS教程 教你制作古老的石头[@more@] 1.打开 Photoshop 新建一个文件,宽度:自定;高度: 自定; RGB模式;白色底色. 新建一个图层并命名为,然后用灰色填充整个图层,再将图层的不 ...
- Android游戏开发:SurfaceView多点触控之完美钢琴游戏Demo
一.我们在使用SurfaceView开发小游戏时,如果需要在窗体上自绘按钮和可交互对象,这时需要监听屏幕的多点触控,并且每次触控的改变都需要和游戏产生交互,如何实现呢? CSDN博客 @MXout 有 ...
- ios触摸超出_iOS开发笔记之多点触控(一)处理触摸的4个方法
多点触控乃苹果公司带给世界的创新之首,作为移动开发者,熟练掌握多点触控开发技能很有必要. 处理触摸的四个方法: -(void)touchesBegan:(NSSet *)touches withEve ...
最新文章
- 聋哑六年级计算机课教学进度计划,小学六年级下册信息技术教学计划三篇
- 深入分析 java 8 编程语言规范:Threads and Locks
- 基础才是重中之重~DictionaryK,V里V的设计决定的性能
- itunes未能连接到iphone_FonePaw iPhone Data Recovery mac版(iphone数据恢复工具)
- 树莓派应用实例6:测量土壤湿度(改进WEB发布)
- C# aspx页面动态加载ascx用户控件 及 利用反射调用其内方法
- python opencv输出mp4_Python玩转视频处理(四):视频按场景进行分割
- 兼容IE和Firefox
- Android 调整控件位置和大小(以textView为例,并设置字体与背景颜色)
- 系列教程丨用 Docker 探索开源软件 —— Elasticsearch(一)
- mysql导入大量数据时jbd2 io过高效率低下问题
- 集群通信组件tribes之使用方法
- 计算机进入启动死循环,教你win10重启死循环怎么解决
- bzoj1754[Usaco2005 qua]Bull Math*
- 解决python -m spacy download en_core_web_sm连接不上服务器的方案
- 全球及中国荧光标签色带行业研究及十四五规划分析报告
- HTML学习(二):HTML基础
- IDEA使用java开发时一个奇葩问题
- 3.Sunday算法的一个小优化
- HTML图像、背景、颜色