The more feasible scenario is to load the MainPage and during its loading, check if the user have agreed on the policy or not. If not, the app navigates to the policy. Sounds simple, doesnt it? No its not.
What should happen if the user reject the agreement? The app should close itself, right? Sorry, this can not happen in Silverlight apps (its possible in XNA though). There is not single command in Silverlight that gets the app to shutdown.
You can create a setting called “AgreedToPrivacyPolicy” and assign to it a “TRUE” value after the user agrees to it. The main trick here is that on the policy page you should put only one button “I Agree”. Do not put an “I Don’t Agree” button because there is no command to handle it straight forward. To facilitate the use of the IsolatedStorageSettings in the application, identify the settings in the “Partial Public Class MainPage” like this:
Partial Public Class MainPage
Private appSettings As System.IO.IsolatedStorage.IsolatedStorageSettings = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings
'the End Class comes at the end of the app code
In the MainPage_Loaded sub put the code:
Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded
If appSettings.Contains("AgreedToPrivacyPolicy") = False Then
NavigationService.Navigate(New Uri("/PrivacyPolicy.xaml", UriKind.Relative))
GoTo Jumpiiii 'Yes I love to use GoTo in VB
If NavigationService.CanGoBack = True Then NavigationService.RemoveBackEntry()
Line 6 is very important, and I will explain to you why later on.
NavigationService.Navigate(New Uri("/MainPage.xaml", UriKind.Relative))
Private Sub Page1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded
Line 2 here removes the MainPage from the back list such that when the user presses back, the user goes directly out of the app without invoking an exception. This is, in my opinion, the best way to exit and application.
One more thing is the case where the user accepts the agreement and then the app navigates to the MainPage. What happens if the user presses back from there? Will the user be navigated back to the PrivacyPolicy page? The answer is NO. Because we covered that already in line 6 in the first code snippet in this article. We told the MainPage to check if there is a previous page in the Back Stack and if there is, erase it.