我需要取消设备后退按钮事件。我已尝试发布在Control press "back button" and disable close the application using a dialog for confirm - wp7中的解决方案,但它不适合我。难道我做错了什么?从对话框中选择确定或取消的应用程序总是退出。Windows Phone 7取消硬件后退按钮不起作用
这里是我的代码...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using System.Windows.Media.Imaging;
using System.Windows.Resources;
namespace GodTools
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.CordovaView.Loaded += CordovaView_Loaded;
BackKeyPress += OnBackKeyPressed;
}
private void CordovaView_Loaded(object sender, RoutedEventArgs e)
{
this.CordovaView.Loaded -= CordovaView_Loaded;
// first time load will have an animation
Storyboard _storyBoard = new Storyboard();
DoubleAnimation animation = new DoubleAnimation()
{
From = 0,
Duration = TimeSpan.FromSeconds(0.6),
To = 90
};
Storyboard.SetTarget(animation, SplashProjector);
Storyboard.SetTargetProperty(animation, new PropertyPath("RotationY"));
_storyBoard.Children.Add(animation);
_storyBoard.Begin();
_storyBoard.Completed += Splash_Completed;
}
void Splash_Completed(object sender, EventArgs e)
{
(sender as Storyboard).Completed -= Splash_Completed;
LayoutRoot.Children.Remove(SplashImage);
}
void OnBackKeyPressed(object sender, System.ComponentModel.CancelEventArgs e)
{
var result = MessageBox.Show("Do you want to exit?", "Attention!",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
// Do not cancel navigation
return;
}
e.Cancel = true;
}
}
}
也看到,同样的问题从科尔多瓦侧 "backbutton" event won't fire
感谢您的信息。我确实想使用硬件后退按钮。我只是想一次一件事地做事。最后,我需要按照后退事件,然后使用JavaScript执行导航。在我这样做之前,我需要取消默认的按钮行为。 – 2012-08-06 18:14:07
好吧,无论如何,你的代码适合我。你有没有试图在Debian中使用OnBackKeyPressed方法?当您按取消按钮时,代码是否转到e.Cancel = true语句? – 2012-08-06 18:18:03
我的代码确实去e.Cancel并将其设置为true,但应用程序仍然退出。 – 2012-08-06 18:21:34