Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show different pages when app launches time in windows phone 7?

When app launches time need to show the registration page.once user registered it shouldn't goes to registration page need to go log in page. How to achieve this?

like image 769
user1237131 Avatar asked Mar 12 '12 09:03

user1237131


2 Answers

You can navigate to the start page of a Windows Phone app from code.

Remove the "DefaultTask" entry from the WMAppManifest

Remove the NavigationPage attribute from the "DefaultTask" in WMAppManifest, and in the Launching event of your app use the something like the example below to navigate to the page of choice upon launch.

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        if (registered)
        {
           ((App)Application.Current).RootFrame.Navigate(new Uri("/<your start page>.xaml", UriKind.Relative));
        }
        else
        {
           ((App)Application.Current).RootFrame.Navigate(new Uri("/<your registration page>.xaml", UriKind.Relative));
        }

    }

You just have to decide how you want to determine that someone already registered.

like image 123
Willem van Rumpt Avatar answered Sep 29 '22 12:09

Willem van Rumpt


I guess you haven't put a lot of thought to this, the setup is pretty easy! When a user registers you could set a variable in the settings defining that a user already has registered. When the application starts, evaluate this setting and if the user registered you show the register-page, otherwise the login-page. Example:

//After (succesful) registration
Properties.Settings.Default.HasRegistered = true; 
Properties.Settings.Default.Save();

//Check the value
var hasRegistered = Properties.Settings.Default.HasRegistered;
if(hasRegistered)
    //show Login
else
    //show Registration

You can also use the IsolatedStorageSettings.ApplcationSettings to do this. The code below is just sample code, you'll have to provide validation if the settings already exist on the first startup of the app and set a default value 'false' for the setting if no registration has occured yet.

//After registration
var settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("HasRegistered"))
    settings["HasRegistered"] = true;
settings.Save();

//Check value
var settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("HasRegistered"))
{
    var registered = bool.Parse(settings["HasRegistered"]);
    if(registered)
        //show login
    else
        //show registration
}

Hope this helps!

like image 21
Abbas Avatar answered Sep 29 '22 14:09

Abbas