DarthVegan
DarthVegan

Reputation: 1269

Writing code to only run when windows phone app is run for the first time

    private const string TERMS_KEY = "Terms";
        private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;

public MainPage()
        {
            InitializeComponent();

            string value;
            if (appSettings.TryGetValue(TERMS_KEY, out value) == false)
            {
                // means this is the first time they have started the application
                NavigationService.Navigate(new Uri("/Terms.xaml", UriKind.Relative));
            }
        }

The code above doesn't work because I'm thinking that I have it in the wrong place in the program flow because I'm getting a null exception when it tries to navigate to the page but nothing in the code is showing up as null. I know this is probably an easy question but I searched online first and couldn't seem to find an answer anywhere.

Upvotes: 0

Views: 38

Answers (1)

Kulasangar
Kulasangar

Reputation: 9434

Are you getting the null exception before getting into the if loop or after?

Is the TERMS_KEY giving any sort of value when you run the application?

Check the navigation Uri too.

Upvotes: 1

Related Questions