How to change the start page in a WP7 application

I want to have a different start page depending on whether there are any settings saved in IsolStorage.

Bu I do not know where it is best to deal with this. I. If I find something in isolated storage, I want the user to get MainPage, otherwise I woluld, as the user, will get the settings page.

I use MVVM-light if there is any magic material to use.

Vg

+6
source share
1 answer

You can do this by setting the dummy page as the main page of your project. You can change the main page by editing the WMAppManifest.xml file of your project:

<DefaultTask Name="_default" NavigationPage="DummyPage.xaml" /> 

Now identify all the navigation files directed to the dummy page, and redirect to any page you want.

To do this, subscribe to the "Navigation" event in the App.xaml.cs file at the end of the constructor:

 this.RootFrame.Navigating += this.RootFrame_Navigating; 

In the event handler, determine whether the navigation is directed to the dummy page, cancel the navigation and redirect to the desired page:

 void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e) { if (e.Uri.OriginalString == "/DummyPage.xaml") { e.Cancel = true; var navigationService = (NavigationService)sender; // Insert here your logic to load the destination page from the isolated storage string destinationPage = "/Page2.xaml"; this.RootFrame.Dispatcher.BeginInvoke(() => navigationService.Navigate(new Uri(destinationPage, UriKind.Relative))); } } 

Edit

Actually, it’s even easier there. at the end of the application constructor, just install UriMapper with the Uri replacement you want:

 var mapper = new UriMapper(); mapper.UriMappings.Add(new UriMapping { Uri = new Uri("/DummyPage.xaml", UriKind.Relative), MappedUri = new Uri("/Page2.xaml", UriKind.Relative) }); this.RootFrame.UriMapper = mapper; 
+9
source

Source: https://habr.com/ru/post/908253/


All Articles