0

I am developing a simple WP8 application using VS 2013. I have a MainPage.xaml and added a new page called Page1.xaml. I have a list of options on screen when a user clicks on "new item" I want to open a new page to add new item (Page1.xaml for instance).
On the list selection changed event I have written the following code:

    private void OptionssList_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var selection = (MenuItem) e.AddedItems[0];
        switch (selection.Id)
        {
            case 0:
                break;
            case 1:
                break;
            case 2:
                this.NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
                break;
            case 3:
                break;
            default:
                break;
        }
    }

When I try to debug the application, I notice that the constructor of Page1.xaml is invoked if I had an OnNavigatedTo event handler it is also been invoked however after all this an Unhandled exception is thrown. There is no code that I can see when the exception is thrown however it invokes the Application_UnhandledException event handler.

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
        if (Debugger.IsAttached)
        {
            // An unhandled exception has occurred; break into the debugger
            Debugger.Break();
        }
    }

The exception details is as shown below:

System.NullReferenceException was unhandled
Message: An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.ni.dll
Additional information: Object reference not set to an instance of an object.

I would like to know if I am missing something. I referred to the sample it also shows similar way to Navigate, did not notice any things fancy.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Nithyanand K N
  • 45
  • 2
  • 10
  • 1
    Maybe we're going to need a little bit more details to understand what happens. There's probably a problem into your Page1.xaml, does it contain something special? – AirL Oct 20 '13 at 09:09
  • There is nothing special on my page one.. I have just created a new page I have not added any control to it yet. – Nithyanand K N Oct 24 '13 at 17:26

1 Answers1

0

i know this may be a very stupid question, your code looks fine to me, is your page not maybe in another folder? I always put my pages in a folder called UI, so my code will look something like this:

                                         /folder1/folder2/pagename
this.NavigationService.Navigate(new Uri("/UI/Generics/Page.xaml", UriKind.Relative));

Just make sure of that, cause that usually get me.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Arrie
  • 1,327
  • 5
  • 18
  • 39