App流程就是这样;
现在我想到了两个解决方案,请帮助我解决这个问题。
答:我应该有“确定”按钮;如果用户点击它,那么主菜单应该打开B。在后退按钮中写什么,这样应用程序就不会终止。
在app.xaml中
专用静电测定仪;
public static Geolocator Locator
{
get
{
lock (typeof(App))
{
if (locator == null)
{
locator = new Geolocator();
locator.DesiredAccuracy = PositionAccuracy.High;
//locator.MovementThreshold = 50;
locator.ReportInterval = 10000;
}
}
return locator;
}
}在MainPage.xaml.cs中
保护覆盖无效OnNavigatedTo(NavigationEventArgs e) { App.Locator.PositionChanged += Locator_PositionChanged;}
谢谢
发布于 2014-02-24 07:55:18
最有可能的是,没有办法做到这一点。
您可以重写后退按钮点击事件,但不能覆盖主按钮事件。
此外,您甚至不能以编程方式调用本机home按钮事件。
在msdn论坛有一个类似问题的链接
更新.你仍然认为,问题在于后退和菜单按钮。这在我看来是不对的。问题是,当Application_Closing事件被击中时,后台代理没有被激活。
App.xaml.cs中有两种方法:
Application_Deactivated和Application_Closing.如果您的后台任务被执行,您的后台任务应该是活动的。
// Code to execute when the application is deactivated (sent to background, e.g. menu button is hit)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
}在后台代理构造函数中设置一个断点,并查看是否已命中。
顺便提一下,对于你的两种解决方案:
解决方案A不能完成。解决方案B可以通过重写OnNavigatedFrom方法来完成。
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
// nothing will happen here
//base.OnNavigatedFrom(e);
}然而,这将是对windows-phone导航服务本机行为的粗暴违反。不会通过认证的。
https://stackoverflow.com/questions/21980706
复制相似问题