1.在<phone:PhoneApplicationPage
中写入BackKeyPress="PhoneApplicationPage_BackKeyPress"事件. 该事件在用户按下back实体键后触发.
本身silverlight 没有程序退出机制,所以我们采用了龌龊抛异常的方法已达到退出应用程序目的
2.实现这个PhoneApplicationPage_BackKeyPress事件
//退出应用
private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
MessageBoxResult res = MessageBox.Show("您确认退出吗?", "提示", MessageBoxButton.OKCancel);
if (res == MessageBoxResult.OK)
{
}
else
{
e.Cancel = true;
}
}
catch
{
}
}
3.定义一个异常类。sl当中没有退出机制,所以使用抛异常的方法实现程序退出
public class QuitException : Exception
{
public static void Quit()
{
throw new QuitException();
}
}