Windows Phone 7 ManipulationStarted 事件

简介:

System.WindowsUIElement.ManipulationStarted 事件

当输入设备对 UIElement 对象开始操作时发生。

ManipulationStarted 事件在 ManipulationStarting 事件之后发生。 使用 ManipulationStartedEventArgs,您可以执行以下操作。

使用 ManipulationContainer 属性获取操作位置所相对的元素。

使用 ManipulationOrigin 属性获取操作的原点。

通过调用 Complete 方法来取消该操作。

小例子:点击界面,触发事件 随机生成hello world

 

 

<!--LayoutRoot contains the root grid where all other page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="UIElement对象操作开始触发事件" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="main page" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Name="txtblk"
Text=""
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</Grid>

事件处理

//在 ManipulationStarted 事件发生时调用,当输入设备对 UIElement 对象开始操作时发生。 
protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
{
TextBlock newTextBlock = new TextBlock();
newTextBlock.Text = "Hello, world!";
newTextBlock.HorizontalAlignment = HorizontalAlignment.Left;//父元素水平最左边
newTextBlock.VerticalAlignment = VerticalAlignment.Top;//父元素垂直最左边
newTextBlock.Margin = new Thickness(
(ContentPanel.ActualWidth - txtblk.ActualWidth) * rand.NextDouble(),
(ContentPanel.ActualHeight - txtblk.ActualHeight) * rand.NextDouble(),
0, 0);
//Thickness 结构四个 Double 值分别描述矩形的四个边(Left、Top、Right 和 Bottom)。
ContentPanel.Children.Add(newTextBlock);

args.Complete();//完成操作
args.Handled = true;//获取或设置将路由事件标记为已处理的值。设置为 true,则可以防止事件路由路径上的大多数处理程序再次处理同一事件。 
base.OnManipulationStarted(args);//务必调用基本类的 OnManipulationStarted 方法,从而基本类接收该事件
}



本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1079167

相关文章
|
消息中间件 安全 API
C#实现操作Windows窗口句柄:SendMessage/PostMessage发送系统消息、事件和数据【窗口句柄总结之二】
SendMessage/PostMessage API 可以实现发送系统消息,这些消息可以定义为常见的鼠标或键盘事件、数据的发送等各种系统操作......
7306 1
C#实现操作Windows窗口句柄:SendMessage/PostMessage发送系统消息、事件和数据【窗口句柄总结之二】
|
7月前
|
存储 安全 UED
Cyber Triage 3.13 for Windows - 数字取证和事件响应
Cyber Triage 3.13 for Windows - 数字取证和事件响应
199 71
Cyber Triage 3.13 for Windows - 数字取证和事件响应
|
9月前
|
缓存 安全 网络协议
使用事件日志识别常见 Windows 错误
事件查看器是Windows操作系统中的标准诊断工具,用于记录系统事件,包括硬件问题、软件中断和系统行为等详细信息。通过分析这些日志,管理员能够追踪和解决系统错误。访问方法包括使用快捷键Win + R输入eventvwr.msc,或通过控制面板进入。事件查看器中的每条记录包含事件ID、来源和描述,帮助识别和解决问题。常见错误如蓝屏死机、DLL错误、驱动程序错误等,可通过更新驱动程序、运行系统诊断、使用恢复功能等方式解决。
585 4
|
Android开发 iOS开发 Windows
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
不久前,随着最后一家WP手机厂商惠普宣布取消今后Windows Phone的研发计划,以及微软官方声明对WP8.1系统今后所有升级维护的终止,WP手机,作为曾经和安卓手机、苹果手机并驾齐驱的三大智能手机之一,正式寿终正寝。
1802 0
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
在Windows 10的事件查看器中查看打印日志
在Windows 10的事件查看器中查看打印日志
在Windows 10的事件查看器中查看打印日志
|
XML 开发框架 前端开发
Windows Phone快速入门需掌握哪些能力
在此之前,先普及下Windows Phone的概念和开发工具的介绍。 Windows Phone是微软公司开发的手机操作系统,它将微软旗下的Xbox Live游戏、Xbox Music音乐与独特的视频体验集成至手机中。2012年6月21日,微软正式发布Windows Phone 8,采用和Windows 8相同的Windows NT内核,同时也针对市场的Windows Phone 7.5发布Windows Phone 7.8。
305 0
Windows Phone快速入门需掌握哪些能力
|
移动开发 Android开发 开发者
Windows Phone 8.1 新功能汇总 开发者预览版开放下载
在Build 2014大会上,微软正式发布了传闻已久的Windows Phone 8.1系统,所有的Windows Phone 8手机都可以升级,微软这次可谓是十分厚道。虽然并非迭代升级,但WP 8.1还是拥有很多重大更新,对于微软进一步完善移动平台拥有积极的意义。下面,就一起来了解一下WP 8.1的主要新特性。
350 0
Windows Phone 8.1 新功能汇总 开发者预览版开放下载
|
调度 Windows
Windows多线程——临界区、事件、互斥量、信号量详解加代码
Windows多线程——临界区、事件、互斥量、信号量详解加代码
718 0
|
安全 调度 数据库
Windows开发——临界区,互斥量,信号量,事件的简单介绍与区别
Windows开发——临界区,互斥量,信号量,事件的简单介绍与区别
671 0
|
Windows
Windows程序设计——窗口键盘消息滚动事件
Windows程序设计——窗口键盘消息滚动事件
347 0