按下窗口按钮后恢复时的导航问题-WP8.1 C#
本文关键字:问题 导航 -WP8 窗口 按钮 恢复 | 更新日期: 2023-09-27 18:12:06
WP8.1 Silverlight应用程序
我已经设置了一个urimapper,可以根据不同的条件启动不同的页面。在应用程序构造函数中调用函数SetUriMapper
应用程序xaml
<UriMapper:UriMapper x:Name="mapper">
<UriMapper:UriMapping Uri="/RootPage.xaml" />
</UriMapper:UriMapper>
应用程序.xaml.cs
public App()
{
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
// Standard Silverlight initialization
InitializeComponent();
// Phone-specific initialization
InitializePhoneApplication();
// Database functions
SetupUriMapper();
}
void SetupUriMapper()
{
// Get the UriMapper from the app.xaml resources, and assign it to the root frame
UriMapper mapper = Resources["mapper"] as UriMapper;
RootFrame.UriMapper = mapper;
if (condition)
{
mapper.UriMappings[0].MappedUri = new Uri("/Walkthrough.xaml", UriKind.Relative);
}
else if (condition2)
{
mapper.UriMappings[0].MappedUri = new Uri("/ResetPasswordPrompt.xaml", UriKind.Relative);
}
else
mapper.UriMappings[0].MappedUri = new Uri("/MainPage.xaml", UriKind.Relative);
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// reading data from database
CycleManager cycMan = CycleManager.Instance;
using (DBManager dbMan = new DBManager())
{
dbMan.OpenConnection();
dbMan.ReadSettingsData(cycMan.ActiveAccount);
}
}
现在用户已进入页面B,并按下主页按钮。然后转到应用程序列表,再次选择该应用程序。调用Application_Activated
并将其导航到页面B。但不到一秒钟,它就导航回MainPage。
但是,如果用户按下后退按钮继续,它会导航到页面B并停留在那里。
行为很奇怪,有线索吗?
这种行为是因为快速应用程序恢复功能WP8。
您需要设置ActivationPolicy
以及重置导航的事件。此链接为您提供了如何将应用程序恢复到您停止的位置的详细信息。
Ed Glogowski的博客