0
votes

I'm trying to go to another xaml page when listbox item in current xaml page clicked. Here is how I did.

 private void mainList_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (mainList.SelectedIndex == -1)
            return;

        NavigationService.Navigate(new Uri("/RegisterSurveyee.xaml",UriKind.Relative));
    }

but it gives me "NULLREFERENCEEXCEPTION" error. groupID groupName are not null. When I change last sentence to this.Content=new RegisterSurveyee(), it works fine. The problem occurs only at NavigationService.Navigate(new Uri("/RegisterSurveyee.xaml",UriKind.Relative)); any help???

1
You need to debug your code to see where the null reference is throwing the exception. Place a break point in the method and step through it. It could be that the added item is not of type SurveyWindowsPhone.Tables.SurveyGroup, hence the casting fails. My hunch is that it's where you are setting the group Id.FunksMaName
possible duplicate of What is a NullReferenceException and how do I fix it?user1228

1 Answers

0
votes

i) Make sure that e.AddedItems[0] is not null and it is of type SurveyGroup

If you are getting null reference exception,

 if (mainList ==null || mainList.SelectedIndex == -1)
            return;

ii) When Navigating from one page to another, you have to give to full name including .xaml extension

 NavigationService.Navigate(new Uri("/RegisterSurveyee.xaml",UriKind.Relative));

If you are still getting NullReference Exception, try registering to the SelectionChanged Event on the Loaded event of the Page.

    private void MainPage_OnLoaded(object sender, RoutedEventArgs e)
    {
        ListBox.SelectionChanged += ListBoxSelectionChanged;
    }