我想知道如何表示應用程序是第一次啓動還是以前已啓動。我想這樣做的原因是在應用程序被使用之前顯示非常簡短的信息消息,而應用程序每隔一段時間都不會顯示。我將使東西在App.xaml.cs像下面如何在首次啓動應用程序時顯示頁面
var settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("WasLaunched"))
{
MessageBox.Show("First time to launch");
settings.Add("WasLaunched", true);
}
如果(!settings.Contains("WasLaunched")
導航到「第一啓動頁」,而不是「主頁」?有人能指出我對這個實現有什麼好的參考嗎?
編輯**
我改變了我的WMAppManifest.xml
默認頁LaunchPage.xaml
<DefaultTask Name="_default" NavigationPage="LaunchPage.xaml" />
而且創建了UriMapper類
public class LoginUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
if (uri.OriginalString == "/LaunchPage.xaml")
{
if (Settings.FirstLoad.Value == true)
{
//Navigate to Welcome Page with quick first time user info
uri = new Uri("/Views/WelcomePage.xaml", UriKind.Relative);
}
else
{
///Navigate to the actual Main Page
uri = new Uri("/MainPage.xaml", UriKind.Relative);
}
}
return uri;
}
}
但是如何更改App.xaml.cs相應
private void Application_Launching(object sender, LaunchingEventArgs e)
{
//how to check and navigate to correct page for this specific method?
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
//how to check and navigate to correct page for this specific method?
}
謝謝,我跟着你的意見d編輯了我上面的第一個問題。在App.xaml.cs中,我現在不確定如何根據應用程序第一次加載還是定期加載來確定要導航到哪個頁面? – Matthew
答覆已更新。你可以檢查代碼。 –
工作很好!我注意到,雖然在點擊WelcomePage並導航到實際的MainPage後,WelcomePage仍然存在於後臺堆棧中。我只需要在MainPage的OnNavigatedTo事件中檢查它,然後相應地從後面的棧中移除頁面?你認爲在這種情況下最好的方法是什麼? – Matthew