Windows 手机 - 如何双击退出? [英] Windows phone - How to exit on double tap?

查看:29
本文介绍了Windows 手机 - 如何双击退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习开发 Windows 手机应用程序.我按照本教程开始使用基于浏览器的应用程序 - http://blogs.msdn.com/b/jaimer/archive/2011/02/04/back-button-press-when-using-webbrowser-control-in-wp7.aspx.我正在试验 http://m.facebook.com 我可以正确使用后退按钮转到上一个页面和所有这些东西,但我无法通过双击后退按钮实现退出.

I'm learning to develop windows phone application. I started with a browser based app by following this tutorial - http://blogs.msdn.com/b/jaimer/archive/2011/02/04/back-button-press-when-using-webbrowser-control-in-wp7.aspx. I'm experimenting with http://m.facebook.com I can correctly use back button to go to the previous page and all that stuff but I'm not able to implement exit on double tap of back button.

我见过许多浏览器应用程序在双击后退按钮后退出.例如 - Flipkart - http://www.windowsphone.com/en-us/store/app/flipkart/84fc03ea-210d-4e3e-88e0-de502a2434c5

I have seen many browsers app which exit after double tapping the back button. for example - Flipkart - http://www.windowsphone.com/en-us/store/app/flipkart/84fc03ea-210d-4e3e-88e0-de502a2434c5

后退按钮没有双标签事件.我们怎样才能做到这一点?

There is no double tab event for back button. How can we achieve this?

推荐答案

您可以创建一个全局 long 表示用户上次按下后退按钮的时间.每次按下后退按钮时,您都可以让您的程序减去经过的滴答数.如果它已经通过了很短的滴答声,你可以让你的程序退出.如果没有,再次设置最后一个刻度变量.

You can create a global long that represents the last time the user pressed the back button. Every time the back button is pressed, you can make your program subtract the number of elapsed ticks. If it has passed a short amount of ticks, you can make your program exit. If not, set the last tick variable once more.

您可以使用 System.DateTime.Ticks 获取代表当前时间的当前刻度.

You can get the current tick that represents the current time with System.DateTime.Ticks.

简单代码示例:

long LastExitAttemptTick = DateTime.Ticks;

private void BackButtonPressHandler(...)
{
    long thisTick = DateTime.Ticks;

    if (LastExitAttemptTick - thisTick < [specified amount])
        throw new Exception("Exit Exception"); //You can use XNA, but this is a quick and dirty way of exiting
    else
        LastExitAttemptTick = DateTime.Ticks;
}

您可以使用 10,000,000 滴答声(1 秒)的值.MSDN 说 10,000每毫秒滴答数,因此 10,000 * 1000 = 10,000,000.

You can use a value of 10,000,000 ticks (1 second). MSDN says 10,000 ticks per millisecond, so 10,000 * 1000 = 10,000,000.

或者如您所说,您也可以使用 DateTime.Now 并改用秒值.无论哪种方式都有效.

Or as you said, you can also use DateTime.Now and use the seconds value instead. Either way works.

这篇关于Windows 手机 - 如何双击退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆