Question

I'm writing a wp8 application and I want a page to load up the first time the app is launched and after that it never appears again, I have been googling for a very long time now and still cant get my head around it, I am only a beginner at this stage and still learning. I no I will need to use isolated storage for this but trying to implement it is a different story. Any help would be very much appreciated. I'm not asking anyone to do it for me, I'm just asking for a bit of guidance.

Was it helpful?

Solution 2

As for the guidance - as you have mentioned IsolatedStorage would be suitable here. In fact IsolatedSotorageSettings will be easiest I think here.

So when your App launches you should determine if it's the first run or not. You can for example in App.xaml.cs modify method Application_Launching, so that it will check if specific key in IsolatedStorageSettings exists if not - it means its the first run ans set up a flag.

After you know if it's the first run (or not) you can try to redirect the Navigation. I think it's well explained on this blog.

You can also try to redirect from MainPage in Loaded event (in this case you can see a blink of MainPage) - it depends what do you want to achieve.

Other way may be - not to Navigate to specific Page - but to change MainPage content, depending on your flag (if it's the very first run).

OTHER TIPS

If you want to launch any page only once after installing the application, you can do so on application launch:

  private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
        if (IsolatedStorageSettings.ApplicationSettings.Contains("IsFirstTimeLaunched") && settings["IsFirstTimeLaunched"] == "true")
        {                   

            Uri nUri = new Uri("/MainPage.xaml", UriKind.Relative);
            RootFrame.Navigate(nUri);       
        }
        else
        {   settings["IsFirstTimeLaunched"] = "true" ;
            settings.Save();
            Uri nUri = new Uri("/FirstTimeLaunch.xaml", UriKind.Relative);
            RootFrame.Navigate(nUri);
        }           
    }

You can delete also this from inside the app also if at any point of time you want the FirstTimeLaunch page again, Suppose in every 30 days you want to show the instructions again on launch.

Call this method inside MainPage.xaml.cs after APP load

protected override void OnNavigatedTo(NavigationEventArgs e)
{
        if (!App.ViewModel.IsDataLoaded)
        {
            App.ViewModel.LoadData();                
        }

        IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
        if (IsolatedStorageSettings.ApplicationSettings.Contains("IsFirstTimeLaunched") && (string)settings["IsFirstTimeLaunched"] == "true")
        {

            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));                
        }
        else
        {
            settings["IsFirstTimeLaunched"] = "true";
            settings.Save();
            NavigationService.Navigate(new Uri("/FirstLaunch.xaml", UriKind.Relative));
        }           
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top