




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一、基本的程序结构一个需要响应多点触控的 Silverlight 应用程序必须将一个处理程序连接到静态 Touch.FrameReported 事件:1Touch.FrameReported += OnTouchFrameReported;FrameReported 事件是静态 Touch 类的唯一公共成员。处理程序如下所示:1voidOnTouchFrameReported(2objectsender, TouchFrameEventArgs args) 3.4您可以在应用程序中安装多个 Touch.FrameReported 事件处理程序,所有这些事件处理程序都会报告应用程序中任何位置的所有触控事件。二、事件传入参数TouchFrameEventArgsTouchFrameEventArgs 有一个名为 TimeStamp 的公共属性(我还没有机会使用)和三个重要的公共方法:1TouchPoint GetPrimaryTouchPoint(UIElement relativeTo)2TouchPointCollection GetTouchPoints(UIElement relativeTo)3voidSuspendMousePromotionUntilTouchUp()GetPrimaryTouchPoint 或 GetTouchPoints 的参数仅用于报告 TouchPoint 对象的位置信息。您可以将空值用于此参数,位置信息相对于整个 Silverlight 应用程序的左上角。多点触控支持多个手指同时触摸屏幕,触摸屏幕的每个手指(数量存在上限,当前通常为两个)都是一个触摸点。主要触摸点是指在没有其他手指触摸屏幕并且未按下鼠标按钮时触摸屏幕的手指。用一个手指触摸屏幕。这是主要触摸点。在第一个手指仍触摸着屏幕时,将第二个手指放在屏幕上。很显然,第二手指不是主要触摸点。但现在仍将第二个手指放在屏幕上,抬起第一个手指,然后再将其放回到屏幕上。这是主要触摸点吗?不,都不是。仅当没有其他手指触摸屏幕时,才会出现主要触摸点。在实际的多点触控应用程序中,您应该注意不要依赖主要触摸点,因为用户通常不会重视第一次触摸的特定意义。仅为实际触摸屏幕的手指激发事件。对非常接近屏幕但并未触摸屏幕的手指,不会进行悬停检测。基于一个触摸点或多个触摸点激发一个特殊的 Touch.FrameReported 事件。从 GetTouchPoints 方法返回的 TouchPointCollection 包含与特定事件关联的所有触摸点。从 GetPrimaryTouchPoint 返回的 TouchPoint 始终是一个主要触摸点。如果没有与该特定事件关联的主要触摸点,GetPrimaryTouchPoint 将返回 null。即使从 GetPrimaryTouchPoint 返回的 TouchPoint 不是 null,它也不会与从 GetTouchPoints 返回的其中一个 TouchPoint 对象是相同对象,但在传递给这些方法的参数相同时所有属性将相同。TouchPoint 类定义以下四个只读属性,这些属性都由依赖属性支持:Action 属性,类型为 TouchAction(一个具有 Down、Move 和 Up 成员的枚举)。Position 属性,类型为 Point,它相对于作为参数传递给 GetPrimaryTouchPoint 或 GetTouchPoints 方法的元素(或相对于参数为 null 的应用程序的左上角)。Size 属性,类型为 Size。TouchDevice 属性,类型为 TouchDevice。TouchDevice 对象具有两个也由依赖属性支持的只读属性:DirectlyOver 属性,类型为 DirectlyOver(手指下最上面的元素)。Id 属性,类型为 int。DirectlyOver 不必是传递给 GetPrimaryTouchPoint 或 GetTouchPoints 的元素的子项。如果手指在 Silverlight 应用程序内(由 Silverlight 插件对象的尺寸定义),但不在可点击测试控件覆盖的范围内,则此属性可以为空。(具有空背景刷的面板不可点击测试。)若要在多个手指之间区分,ID 属性至关重要。在特定手指触摸屏幕时,与该手指关联的一系列特定事件总是以 Down 操作开始,接着是 Move 事件,最后是 Up 事件。所有这些事件都将与相同的 ID 关联。(但不要以为主要触摸点的 ID 值将为 0 或 1。)大多数重要的多点触控代码都会使用 Dictionary 集合,其中 TouchDevice 的 ID 属性是字典键。这是跨事件存储特定手指信息的方式。三、涂鸦板例子涂鸦板例子 综合运用ApplicationBar菜单、多点触摸和IsolatedStorageFile本地存储0115161718192021222324262932333435363738394041424647515256576162636566686971727475767778001usingSystem;002usingSystem.Collections.Generic;003usingSystem.Windows;004usingSystem.Windows.Ink;005usingSystem.Windows.Input;006usingSystem.Windows.Media;007usingMicrosoft.Phone.Controls;008usingMicrosoft.Phone.Shell;009010namespaceJot011012publicpartialclassMainPage : PhoneApplicationPage013014JotAppSettings appSettings = (Application.CurrentasApp).AppSettings;015Dictionary activeStrokes =newDictionary();016017publicMainPage()018019InitializeComponent();020021inkPresenter.Strokes = appSettings.StrokeCollectionsappSettings.PageNumber;022inkPresenter.Background =newSolidColorBrush(appSettings.Background);023024/ Re-assign ApplicationBar button names025appbarLastButton =this.ApplicationBar.Buttons1asApplicationBarIconButton;026appbarNextButton =this.ApplicationBar.Buttons2asApplicationBarIconButton;027appbarDeleteButton =this.ApplicationBar.Buttons3asApplicationBarIconButton;028029TitleAndAppbarUpdate();030031Touch.FrameReported += OnTouchFrameReported;032/一个需要响应多点触控的 Silverlight 应用程序必须将一个处理程序连接到静态 Touch.FrameReported 事件033034035/处理多点触摸事件036voidOnTouchFrameReported(objectsender, TouchFrameEventArgs args)037038TouchPoint primaryTouchPoint = args.GetPrimaryTouchPoint(null);039040if(primaryTouchPoint !=null& primaryTouchPoint.Action = TouchAction.Down)041args.SuspendMousePromotionUntilTouchUp();042/*043* foreach 循环枚举从 GetTouchPoints 返回的 TouchPointCollection 的 TouchPoint 成员。044* (您会希望多点触控感知 Silverlight 程序能处理多个手指,但您不会希望它在检测到太多手指时出现故障!)ID 将添加到 Down 事件的字典中,然后从 Up 事件的字典中删除。045* */046TouchPointCollection touchPoints = args.GetTouchPoints(inkPresenter);047048foreach(TouchPoint touchPointintouchPoints)049050Point pt = touchPoint.Position;051intid = touchPoint.TouchDevice.Id;052053switch(touchPoint.Action)054055caseTouchAction.Down:056Stroke stroke =newStroke();057stroke.DrawingAttributes.Color = appSettings.Foreground;058stroke.DrawingAttributes.Height = appSettings.StrokeWidth;059stroke.DrawingAttributes.Width = appSettings.StrokeWidth;060stroke.StylusPoints.Add(newStylusPoint(pt.X, pt.Y);061062inkPresenter.Strokes.Add(stroke);063activeStrokes.Add(id, stroke);064break;065066caseTouchAction.Move:067activeStrokesid.StylusPoints.Add(newStylusPoint(pt.X, pt.Y);068break;069070caseTouchAction.Up:071activeStrokesid.StylusPoints.Add(newStylusPoint(pt.X, pt.Y);072activeStrokes.Remove(id);073074TitleAndAppbarUpdate();075break;076077078079080/新增一个页面081voidOnAppbarAddClick(objectsender, EventArgs args)082083StrokeCollection strokes =newStrokeCollection();084appSettings.PageNumber += 1;085appSettings.StrokeCollections.Insert(appSettings.PageNumber, strokes);086inkPresenter.Strokes = strokes;087TitleAndAppbarUpdate();088089/上一个页面090voidOnAppbarLastClick(objectsender, EventArgs args)091092appSettings.PageNumber -= 1;093inkPresenter.Strokes = appSettings.StrokeCollectionsappSettings.PageNumber;094TitleAndAppbarUpdate();095096/下一个页面097voidOnAppbarNextClick(objectsender, EventArgs args)098099appSettings.PageNumber += 1;100inkPresenter.Strokes = appSettings.StrokeCollectionsappSettings.PageNumber;101TitleAndAppbarUpdate();102103/删除当前的页面104voidOnAppbarDeleteClick(objectsender, EventArgs args)105106MessageBoxResult result = MessageBox.Show(Delete this page?,Jot,107MessageBoxButton.OKCancel);108109if(result = MessageBoxResult.OK)110111if(appSettings.StrokeCollections.Count = 1)112113appSettings.StrokeCollections0.Clear();114115else116117appSettings.StrokeCollections.RemoveAt(appSettings.PageNumber);118119if(appSettings.PageNumber = appSettings.StrokeCollections.Count)120appSettings.PageNumber -= 1;121122inkPresenter.Strokes = appSettings.StrokeCollectionsappSettings.PageNumber;123124TitleAndAppbarUpdate();125126127/设置画笔背景颜色128voidOnAppbarSwapColorsClick(objectsender, EventArgs args)129130Color foreground = appSettings.Background;131appSettings.Background = appSettings.Foreground;132appSettings.Foreground = foreground;133inkPresenter.Background =newSolidColorBrush(appSettings.Background);134135foreach(StrokeCollection strokeCollectioninappSettings.StrokeCollections)136foreach(Stroke strokeinstrokeCollection)137stroke.DrawingAttributes.Color = appSettings.Foreground;138139/设置画笔的粗细140voidOnAppbarSetStrokeWidthClick(objectsender, EventArgs args)141142ApplicationBarMenuItem item = senderasApplicationBarMenuItem;143144if(item.Text.StartsWith(light)145appSettings.StrokeWidth = 1;146147elseif(item.Text.StartsWith(medium)148appSettings.StrokeWidth = 3;149150elseif(item.Text.StartsWith(heavy)151appSettings.StrokeWidth = 5;152153154voidTitleAndAppbarUpdate()155156pageInfoTitle.Text = String.Format( - PAGE 0 OF 1,157appSettings.PageNumber + 1,158appSettings.StrokeCollections.Count);159160appbarLastButton.IsEnabled = appSettings.PageNumber 0;161appbarNextButton.IsEnabled =162appSettings.PageNumber 1) |164(appSettings.StrokeCollections0.Count 0);165166167本地存储功能封装的类01usingSystem;02usingSystem.Collections.Generic;03usingSystem.IO;04usingSystem.IO.IsolatedStorage;05usingSystem.Windows;06usingSystem.Windows.Ink;07usingSystem.Windows.Media;08usingSystem.Xml.Serialization;0910namespaceJot1112publicclassJotAppSettings1314publicJotAppSettings()1516this.PageNumber = 0;17this.Foreground = (Color)Application.Current.ResourcesPhoneForegroundColor;18this.Background = (Color)Application.Current.ResourcesPhoneBackgroundColor;19this.StrokeWidth = 3;202122/ Public properties - the actual application settins23publicList StrokeCollections get;set; 24publicintPageNumber set;get; 25publicColor Foreground set;get; 26publicColor Background set;get; 27publicintStrokeWidth set;get; 2829publicstaticJotAppSettings Load()3031JotAppSettings settings;32IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();3334if(iso.FileExists(settings.xml)3536IsolatedStorageFileStream stream = iso.OpenFile(settings.xml, FileMode.Open);37StreamReader reader =newStreamReader(stream);3839XmlSerializer ser =newXmlSerializer(typeof(JotAppSettings);40settings = ser.Deserialize(reader)asJotAppSettings;4142reader.Close();4344else4546/ Create and initialize new JotAppSettings object47settings =newJotAppSettings();48settings.StrokeCollections =newList();49settings.StrokeCollections.Add(newStrokeCollection();505152iso.Dispose();53returnsettings;545556publicvoidSave()5758IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();59IsolatedStorageFileStream stream = iso.CreateFile(settings.xml);60StreamWriter writer =newStreamWriter(stream);6162XmlSerializer ser =newXmlSerializer(typeof(JotAppSettings);63ser.Serialize(writer,this);6465writer.Close();66iso.Dispose();676869app.xaml010708091011121314171819app.xaml.csview sourceprint?001usingSystem;002usingSystem.Windows;003usingSystem.Windows.Navigation;004usingMicrosoft.Phone.Controls;005usingMicrosoft.Phone.Shell;006007namespaceJot008009publicpartialclassApp : Application010011/ Application Settings012publicJotAppSettings AppSettings
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业办公人员管理表格(按员工角色细分)
- 教育资源共享与技术服务协议
- 艺术绘画技巧与能力测试题目集
- 六一写封信活动方案
- 六一商家活动方案
- 六一故事展示活动方案
- 六一泡泡大作战活动方案
- 六一活动充值活动方案
- 六一活动喂兔子活动方案
- 六一活动海边活动方案
- 实验室安全教育课件
- 市政病媒生物防制基础知识练习题及答案(200题)
- 2024江苏省扬州市高一下学期期末考生物试题及答案
- 2023-2024学年河北省唐山市路南区数学五年级第二学期期末监测试题含解析
- 酒店物品艺术赏析智慧树知到期末考试答案章节答案2024年青岛酒店管理职业技术学院
- (高清版)JTGT 3310-2019 公路工程混凝土结构耐久性设计规范
- 探案识证学诊断 知到智慧树网课答案
- (正式版)JTT 1497-2024 公路桥梁塔柱施工平台及通道安全技术要求
- MOOC 园林植物遗传育种学-北京林业大学 中国大学慕课答案
- 抖音种草方案
- 《小石潭记》教学实录及反思特级教师-王君
评论
0/150
提交评论