locked
App.Xaml.cs page code causing Frame.Navigate to fail

    Question


  • I created an extended splash page for my windows store app that works fine but once I try to navigate to a new page and try to add a new item that would also lead to a new page, my code fails and I get the following error:

    Object reference not set to an instance of an object
    Void AppBarButton_Click(System.Object, Windows.UI.Xaml.RoutedEventArgs)

    App.xaml.cs code: //all of which I took from the msdn splash page example

    if(e.PreviousExecutionState != ApplicationExecutionState.Running)
    {
       bool loadState = (e.PreviousExecutionState == ApplicationExecutionState.Terminated);
       ExtendedSplash extendedSplash = new ExtendedSplash(e.SplashScreen, loadState);
       Window.Current.Content = extendedSplash;
    }

    The return parameters are void and the parameter info is void too.

    Not sure what is going on, any help on how to fix this would be great.

    Friday, March 28, 2014 2:19 AM

Answers

  • There was Frame in Window.Current.Content property before you set splashscreen to it. So you lost Frame.

    You can create page with splash screen image and navigate to it. Don't need to rewrite Window.Current.Content property.

    (I have suggested that ExtendedSplash  is Page type):

    Frame.Navigate(typeof(ExtendedSplash ), null);
    
    ....
    somewhere in ExtendedSplash :
    Frame.Navigate(typeof(PictureChooserPage), null);


    Friday, March 28, 2014 2:44 PM

All replies

  • On which line of code is the app failing? It would be easier to troubleshoot this with a sample app.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, March 28, 2014 12:20 PM
    Moderator
  • The error is in my line of code where I navigate to a new page:

    Frame.Navigate(typeof(PictureChooserPage), null);

    I get the system.NullReferenceException.


    Friday, March 28, 2014 12:33 PM
  • What does this code have to do with the previous code?  Is it possible for you to post a project somewhere we can see?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, March 28, 2014 1:13 PM
    Moderator
  • There was Frame in Window.Current.Content property before you set splashscreen to it. So you lost Frame.

    You can create page with splash screen image and navigate to it. Don't need to rewrite Window.Current.Content property.

    (I have suggested that ExtendedSplash  is Page type):

    Frame.Navigate(typeof(ExtendedSplash ), null);
    
    ....
    somewhere in ExtendedSplash :
    Frame.Navigate(typeof(PictureChooserPage), null);


    Friday, March 28, 2014 2:44 PM