How to show the page if the application is launched for the first time

I am wondering how to signal whether the application is running for the first time or has already been started earlier. The reason I want to do this is to show a very short informative message before the application will ever be used, and every time the application starts, nothing is displayed. I would put something in App.xaml.cs as shown below.

var settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("WasLaunched")) 
{
  MessageBox.Show("First time to launch");
  settings.Add("WasLaunched", true);
}

And if you (!settings.Contains("WasLaunched")go to the "first launch page" and not to the "main page"? Can someone point me to any good links to this implementation?

EDIT **

I changed my WMAppManifest.xmldefault page toLaunchPage.xaml

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

And created my UriMapper class

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;
    }
}

But how do I change App.xaml.cs accordingly

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?
}
+1
2

UriMapper

.

:

(EntryPage.xaml) . UriMapper MapUri.

   public class YourUriMapper : UriMapperBase
   {
    public override Uri MapUri(Uri uri)
    {
        if (uri.OriginalString == "/EntryPage.xaml")
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;

            if (!settings.Contains("WasLaunched"))
            {
                 uri = new Uri("/FirstRunInfoPage.xaml", UriKind.Relative);
            }
            else
            {
                 uri = new Uri("/MainPage.xaml", UriKind.Relative);
             }
         }
            return uri;
     } 
  }

, UriMapper :

private void Application_Launching(object sender, LaunchingEventArgs e)
{
    RootFrame.UriMapper = new YourUriMapper();
}

private void Application_Activated(object sender, ActivatedEventArgs e)
{
    if (e.IsApplicationInstancePreserved == false)
    {
      // tombstoned! Need to restore state
      RootFrame.UriMapper = new YourUriMapper();
    }
}
+7

, . , URI-. , , . , , , .

  public App()
    {
        SetUpLandingPageView();
    }


     void SetUpLandingPageView()
    {
        var isLaunched = IsolatedStorageSettings.ApplicationSettings.Contains("WasLaunched");

        // Get the UriMapper from the app.xaml resources, and assign it to the root frame
        var mapper = Resources["mapper"] as UriMapper;

        if (mapper == null) 
            throw new ArgumentNullException("Mapper must be configured");

        RootFrame.UriMapper = Resources["mapper"] as UriMapper;

        // Update the mapper as appropriate
        mapper.UriMappings[0].MappedUri = isLaunched ? new Uri("/Views/HomePage.xaml", UriKind.Relative) : new Uri("/Views/Introduction.xaml", UriKind.Relative);    
    }

app.xaml

:

xmlns:UriMapper="clr-namespace:System.Windows.Navigation;assembly=Microsoft.Phone"

Xaml

 <Application.Resources>
    <ResourceDictionary>
        <UriMapper:UriMapper x:Name="mapper">
            <UriMapper:UriMapping Uri="/MainPage.xaml" />
        </UriMapper:UriMapper>
    </ResourceDictionary>
</Application.Resources>
+3

All Articles