Bohrend
Bohrend

Reputation: 1497

Windows phone extended splash back navigation

I created a extended splash screen for my windows phone app, but now everytime I press back on the home page it reloads the extended splashscreen. Is it possible to remove it from the navigation stack and let the app execute the application_closing event?

code for splash:

public partial class ExtendedSplashScreen : PhoneApplicationPage
{
    public ExtendedSplashScreen()
    {
        InitializeComponent();

        //Call MainPage from ExtendedSplashScreen after some delay            
        Splash_Screen();
    }

    async void Splash_Screen()
    {
        await Task.Delay(TimeSpan.FromSeconds(3)); // set your desired delay            
        NavigationService.Navigate(new Uri("/Screens/HomeScreen.xaml", UriKind.Relative));    
    }

Upvotes: 1

Views: 328

Answers (2)

Olivier Payen
Olivier Payen

Reputation: 15268

Put this code in the HomeScreen.xaml.cs file:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    while (this.NavigationService.BackStack.Any())
    {
        this.NavigationService.RemoveBackEntry();
    }
}

It will clean the backstack, so that the app exits when pressing the back button.

Upvotes: 0

Abhishek
Abhishek

Reputation: 995

yes you can remove it from back stack, try this

int a = NavigationService.BackStack.Count(); while (a > 0) { this.NavigationService.RemoveBackEntry(); a = NavigationService.BackStack.Count(); } Here a > 0 used because nothing should be befour home page.

Upvotes: 0

Related Questions