Windows 8.1 应用开发 – 触控操作
2023-09-11 14:19:53 时间
与WPF相同Windows 8.1应用中也具有高级触控操作(Manipulation),其中包含了三种常见的触屏手势:平移、缩放、旋转,通过以下四种事件可为控件实现各种触控操作:ManipulationStarting、ManipulationStarted、ManipulationDelta、ManipulationInertiaStarting、ManipulationCompleted。
打开Visual Studio 2013 Preview,新建Windows Store应用。在XAML代码中添加Image控件,将ManipulationMode设置为ALL(也可按需要选择不同模式),并为其添加ManipulationStarting、ManipulationDelta、ManipulationCompleted事件,以便后续实现相关手势操作内容。RenderTransform中的CompositeTransform是一个控件变形组合,可容纳多种变形属性,如平移、旋转、缩放。
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Canvas> <Image x:Name="imageElement" Source="images/cliff.jpg" Height="460" Width="758" Canvas.Left="300" Canvas.Top="150" ManipulationMode="All" ManipulationStarting="image_ManipulationStarting" ManipulationDelta="image_ManipulationDelta" ManipulationCompleted="image_ManipulationCompleted"> <Image.RenderTransform> <CompositeTransform x:Name="imageCT"/> </Image.RenderTransform> </Image> </Canvas> </Grid>
接下来,编写每个事件的具体内容,如下代码:
private void image_ManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e) { e.Handled = true; } private void image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { FrameworkElement element = e.OriginalSource as FrameworkElement; element.Opacity = 0.5;
imageCT.TranslateX += e.Delta.Translation.X; imageCT.TranslateY += e.Delta.Translation.Y; imageCT.ScaleX *= e.Delta.Scale; imageCT.ScaleY *= e.Delta.Scale; imageCT.Rotation += e.Delta.Rotation; }
private void image_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) {
FrameworkElement element = e.OriginalSource as FrameworkElement; element.Opacity = 1; }
这些代码很好理解,当ManipulationDelta触发后,首先将控件透明度设置为0.5,然后捕捉触控操作并对TranslateX、TranslateY(平移);ScaleX、ScaleY(缩放)、Rotation(旋转)进行修改。最后ManipulationCompleted结束后将控件透明度恢复即可。按下F5键看看效果如何。
相关文章
- Windows核心编程 第五章 作业(上)
- 线程操作与进程挂起(Windows核心编程)
- Windows域的管理
- windows相关笔记
- Airtest自动化测试实操案例 | Windows应用篇
- windows下通过VNC图形化訪问Ubuntu桌面环境
- Windows系统DNS部署与安全
- docker for windows--Windows 10 家庭中文版安装kali并配置更新源
- Windows下 Qt 资源文件(.qrc)文件 的 编写与应用
- 【Windows】+ windows下在某一文件夹下按“shift+鼠标右键”打开CMD窗口
- Windows设置防火墙允许指定应用正常使用网络
- Windows 10 IoT Serials 8 – 如何改变UWP应用的目标平台
- Google protocol buffer在windows下的编译
- 《SAS 统计分析与应用从入门到精通(第二版)》一1.2 SAS for Windows的安装和启动
- 关于在windows平台下将应用制作成windows服务及服务依赖的感想
- 【转载】 SLI导致双显卡被TensorFlow同时占用问题(Windows下) ---------- (windows环境下如何为tensorflow安装多个独立的消费级显卡)
- 安装SQL Server 2012过程中出现“启用windows功能NetFx3时出错”(错误原因、详细分析及解决方法)以及在Windows Server2012上安装.NET Framework 3
- 使用 XAML 编写 Windows Presentation Foundation (WPF) 应用
- Ceres Solver 在windows visual studio 2017安装
- windows下Oracle Tuxedo编译应用前需要配置的相关环境变量
- Windows 10将很快允许用户在未安装应用之前首先进行体验
- Windows 8.1 新增控件之 Flyout
- 基于Windows下永久破解jetbrains公司的系列产品(Idea, pycharm,clion,phpstorm)
- Windows Phone真的没救了?被曝应用商城满是虚假应用
- SQL Server windows身份验证和SQL Server身份验证的连接字符串
- 微软翻译软件下个月起停止支持较旧的Windows设备
- Skype应用将在7月1日停止支持Windows Phone 8/8.1等系统
- Windows平台下Git(gitblit)服务器搭建