0

I get an error when I try to navigate between pages in my WPF program, here is my code:

            DataAccess db = new DataAccess();
            int newid = db.AddCar(car);
            HomePage homePage = new HomePage(newid);
            this.NavigationService.Navigate(homePage);

from this code, I navigate to the HomePage page (this navigation is working ok), and then in the HomePage:

        public HomePage(int newid)
    {
        CarDetails carDetails = new CarDetails(newid);
        this.NavigationService.Navigate(carDetails);
    }

This is the code which is running and failing - the error I get is:

System.NullReferenceException: 'Object reference not set to an instance of an object.' System.Windows.Controls.Page.NavigationService.get returned null.

The idea is after the user is adding a new car, it auto navigates to CarDetails about the new car he just added, and the previous page suppose to be HomePage and not the page of the new car adding. Why is it happenning? Thanks for any help!

  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Cleptus Jan 29 '21 at 18:57
  • Can you enter the NavigationService code? – Lucas Ethen Jan 30 '21 at 12:28

0 Answers0