windows phone 开发常用小技巧 - 退出应用之升级版(三秒内双击退出)

//设置一个DispatcherTimer,控制三秒内再次点击返回键时执行退出逻辑
 public void ExitBy2Click(System.ComponentModel.CancelEventArgs e)
        {
            if (!IsExit)
            {

                IsExit = true;
                e.Cancel = true;
                _timer = new DispatcherTimer();
                _timer.Start();
                SystemTrayMessage.Instance.StartAdv("再按一次退出", 3, false);
                _timer.Interval = TimeSpan.FromSeconds(3);
                _timer.Tick += (sender, ee) =>
                {
                    IsExit = false;
                    e.Cancel = false;
                    _timer.Stop();
                };

                return;
            }
            else
            {       
                while (NavigationService.BackStack.Any())
                    NavigationService.RemoveBackEntry();
                base.OnBackKeyPress(new CancelEventArgs());
               // App.Current.Terminate();
                //new Microsoft.Xna.Framework.Game().Exit();//wp7
            }
posted @ 2014-08-09 07:32  zhaowh  阅读(162)  评论(0编辑  收藏  举报