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

相关文章
|
Android开发 iOS开发 Windows
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
不久前,随着最后一家WP手机厂商惠普宣布取消今后Windows Phone的研发计划,以及微软官方声明对WP8.1系统今后所有升级维护的终止,WP手机,作为曾经和安卓手机、苹果手机并驾齐驱的三大智能手机之一,正式寿终正寝。
1252 0
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
|
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。
135 0
Windows Phone快速入门需掌握哪些能力
|
编解码 前端开发 JavaScript
Windows Phone 下开发 LBS 应用
基于位置的服务(Location Based Service,LBS),它是通过电信移动运营商的无线电通讯网络(如GSM网、CDMA网)或外部定位方式(如GPS)获取移动终端用户的位置信息(地理坐标,或大地坐标),在GIS(Geographic Information System,地理信息系统)平台的支持下,为用户提供相应服务的一种增值业务。
162 0
|
移动开发 Android开发 开发者
Windows Phone 8.1 新功能汇总 开发者预览版开放下载
在Build 2014大会上,微软正式发布了传闻已久的Windows Phone 8.1系统,所有的Windows Phone 8手机都可以升级,微软这次可谓是十分厚道。虽然并非迭代升级,但WP 8.1还是拥有很多重大更新,对于微软进一步完善移动平台拥有积极的意义。下面,就一起来了解一下WP 8.1的主要新特性。
230 0
Windows Phone 8.1 新功能汇总 开发者预览版开放下载
|
Windows 数据安全/隐私保护 C#