0

As we all know we have to define default navigating page in WMAppManifest file. I've MainPage.xaml page as default, but I want to Navigate to some other Page on application launch. I do not want to remove MainPage from WMAppManifest file.

Currently I had tried the following things

  • On MainPage loaded I'm navigating to the second Page.
  • In App.xaml.cs I've set the following code in CompleteInitializePhoneApplication method

    RootFrame.Source = new Uri("/Songslist.xaml", UriKind.RelativeOrAbsolute);
    

Both are working but the app hangs for seconds during navigating which gives bad looks. I can't upload the sceenshot because it happens for seconds. How could I achieve this thing? When I do with the following code I got NullReference Exception because RootVisual=null

    (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Songslist.xaml", UriKind.RelativeOrAbsolute));
Amit Singh
  • 2,698
  • 21
  • 49
  • You can find three different solution in this question asked yesterday : http://stackoverflow.com/questions/19169657/how-to-change-start-page-at-startup/19170032?noredirect=1#comment28360898_19170032 – Benoit Catherinet Oct 04 '13 at 13:36

1 Answers1

4

You should us an UriMapper, it will allow you to redirect the app to a specific page based on conditions. Here is how to do:

At the end of the Application constructor in the App.xaml.cs, set the RootFrame.UriMapper to a new UriMapper that does the redirection:

var mapper = new UriMapper();
string page = "/Songslist.xaml";

// Here you map "MainPage.xaml" to "Songslist.xaml"
mapper.UriMappings.Add(new UriMapping
{
    Uri = new Uri("/MainPage.xaml", UriKind.Relative),
    MappedUri = new Uri(page, UriKind.Relative)
});

this.RootFrame.UriMapper = mapper;

The advantage is that it shouldn't hang anymore, and there won't be MainPage.xaml in the back stack.

Olivier Payen
  • 15,198
  • 7
  • 41
  • 70