设为首页 收藏本站
查看: 1134|回复: 0

Windows Phone 7 编程实践—捕获Map控件的DoubleTap事件

[复制链接]

尚未签到

发表于 2015-5-9 13:55:31 | 显示全部楼层 |阅读模式
DSC0000.jpg
作品目标:Windows Phone 7 开发的实用手册
Windows Phone 7 编程实践--捕获Map控件的DoubleTap事件。
DoubleTap事件的放大功能需要下载新的地图信息,会给用户带来不小的流量负担,因此程序自主控制地图的缩放功能很有必要。
参考资料
Touch Gestures on Windows Phone

目录
提出问题    1
Map Members    1
分析问题    3
依据原有经验,重载OnManipulationStarted方法    3
从触控手势入手,判断TouchTap的手势方法中寻找曙光    3
解决问题    4
在MainPage.XAML中添加Canvas和toolkit:GestureService.GestureListener    4
添加Map控件,设置属性    5
在MainPage类中GestureListener_DoubleTap处理代码    5
Debug调试    5


提出问题

MSDN中文论坛—Windows Phone 7开发上有位朋友提出想重载Map的默认的双击事件(Double Tap)。因为双击事件的放大功能需要下载新的地图信息,误操作会给用户带来不小的流量负担。从用户的角度来思考做出的程序,肯定会大受欢迎。
Microsoft.Phone.Controls.Maps.Map默认的双击(Double Tap)事件是修改Map的ZoomLevel属性。那么Map空间的双击(Double Tap)事件如何重载呢,让我们先看看MSDN上关于Map Event的帮助。
Map Members

Windows Phone
DSC0001.png Events
DSC0002.gif

Name

Description

DSC0003.gif

BindingValidationError

(Inherited from FrameworkElement.)

DSC0004.gif

GotFocus

(Inherited from UIElement.)

DSC0005.gif

IsEnabledChanged

(Inherited from Control.)

DSC0006.gif

KeyDown

(Inherited from UIElement.)

DSC0007.gif

KeyUp

(Inherited from UIElement.)

DSC0008.gif

LayoutUpdated

(Inherited from FrameworkElement.)

DSC0009.gif

Loaded

(Inherited from FrameworkElement.)

DSC00010.gif

LoadingError

Occurs when there is an error loading the map. (Inherited from MapCore.)

DSC00011.gif

LostFocus

(Inherited from UIElement.)

DSC00012.gif

LostMouseCapture

(Inherited from UIElement.)

DSC00013.gif

ManipulationCompleted

(Inherited from UIElement.)

DSC00014.gif

ManipulationDelta

(Inherited from UIElement.)

DSC00015.gif

ManipulationStarted

(Inherited from UIElement.)

DSC00016.gif

MapPan

Occurs when the screen is touched and dragged to pan the map. This event occurs every frame. (Inherited from MapCore.)

DSC00017.gif

MapResolved

Occurs when the map tiles are fully downloaded, regardless of whether the user is still interacting with the map. (Inherited from MapCore.)

DSC00018.gif

MapZoom

Occurs when the map is touched to zoom the map. (Inherited from MapCore.)

DSC00019.gif

ModeChanged

Occurs when the map mode changes. (Inherited from MapCore.)

DSC00020.gif

MouseEnter

(Inherited from UIElement.)

DSC00021.gif

MouseLeave

(Inherited from UIElement.)

DSC00022.gif

MouseLeftButtonDown

(Inherited from UIElement.)

DSC00023.gif

MouseLeftButtonUp

(Inherited from UIElement.)

DSC00024.gif

MouseMove

(Inherited from UIElement.)

DSC00025.gif

MouseWheel

(Inherited from UIElement.)

DSC00026.gif

SizeChanged

(Inherited from FrameworkElement.)

DSC00027.gif

TargetViewChanged

Occurs when the view towards which the map is animating changes. (Inherited from MapCore.)

DSC00028.gif

Unloaded

(Inherited from FrameworkElement.)

DSC00029.gif

ViewChangeEnd

Occurs when the view is done changing. (Inherited from MapCore.)

DSC00030.gif

ViewChangeOnFrame

Occurs for every frame of a view change. (Inherited from MapCore.)


ViewChangeStart

Occurs when the view starts changing. (Inherited from MapCore.)


显然,在这里我们找不到关于双击(Double Tap)事件,只能靠我们自己捕获触控手势。
分析问题


依据原有经验,重载OnManipulationStarted方法


依据已有的Silverlight多点触控的经验,在MainPage类中重载OnManipulationStarted处理对于Map的触控。
首先判断触控的来源于Map的话,再去判断是否是双击手势。
protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
{
if (args.OriginalSource == myMap)//myMap是定义的map的name
{
//判断手势,如果是doubleTap则处理
//Silverlight对于手势的判断,有文章专门说明Silverlight应用XNA的手势判断
//……
}
args.Complete();
base.OnManipulationStarted(args);
}
尝试发现DoubleTap触控让Map拦截处理,并没有传入OnManipulationStarted方法中。
想到如果在Map的上层添加一个透明的Button,Button的作用就是截获所有map的触控。这样做虽然达到了阻止DoubleTap事件的处理,但是缺点视乎更难以接受,放弃了所有Map自带的功能,Map的所有功能都要自己实现。
看来此路不通,那我们换一种思路,从触控手势入手,判断TouchTap的手势方法中寻找曙光。

从触控手势入手,判断TouchTap的手势方法中寻找曙光


Charles Petzold有篇文章Touch Gestures on Windows Phone介绍了Silverlight在Windows Phone中判断触控手势,文章中介绍了捕获12种手势(GestureBegin, GestureCompleted, Tap, DoubleTap, Hold, DragStarted, DragDelta, DragCompleted, Flick, PinchStarted, PinchDelta, PinchCompleted)的方法。
具体做法就是在XAML文件中做如下声明:

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-65269-1-1.html 上篇帖子: Windows Phone 7的Panorama(全景视图)控件简介 下篇帖子: Windows Phone 7的Launchers&Choosers简介及其行为浅析
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表