Scenario:
I have a NavigationWindow style like this:
<Style TargetType="NavigationWindow" x:Key="{x:Type NavigationWindow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="NavigationWindow" >
...
</Style>
I start my app with loading a Page called Home.xaml. In Home.xaml I have a button that navigates to another page called PersonalData:
private void btnNewUser_Click(object sender, System.Windows.RoutedEventArgs e)
{
PersonalData personalData = new PersonalData();
this.NavigationService.Navigate(personalData);
}
This works fine and the PersonalData Page gets loaded. On that second Page I have a button "Home" that navigates back to the Home page:
private void btnHome_Click(object sender, System.Windows.RoutedEventArgs e)
{
Home home = new Home();
this.NavigationService.Navigate(home);
}
I use "Navigate" here because I want to reuse that button on later forms too, to always have a button that leads to the start page.
So this also works and the Home page gets loaded. I can even click btnNewUser there a second time and again, the PersonalData page gets opened without any problems.
BUT, when I then click the "Home" button for the second time, I get an error that "this.NavigationService" is null..
I've just started with WPF and I have no idea where to start on fixing this.. Anyone?