Reputation: 1
All! I am working on a WPF application that requires a Menu and Frame. I am using Frame.Navigate, however, if I have 3 or 4 pages open, and I use the back button to go back to the first Page, and then add a new Page, it removes all Pages from the Navigation that were entered forward within the stack. If this is how the Navigate/Menu feature works, how can I add a new Page when navigating anywhere within the Pages without it closing those Pages that reside in front of the new Page? Thanks in advance!
Absolutely! I have a Frame in the XAML
XAML:
<Menu x:Name="mnu" DockPanel.Dock="Top" HorizontalAlignment="Left" Background="#FF0062A0" Foreground="#E2E2E2" FontSize="18" FontWeight="Bold">
<MenuItem Header="_Browse">
<MenuItem.Effect>
<DropShadowEffect/>
</MenuItem.Effect>
<MenuItem Foreground="Black" Header="Page1" Name="Page1" Click="Page1_Click"></MenuItem>
<MenuItem Foreground="Black" Header="Page2" Name="Page2" Click="Page2_Click"></MenuItem>
<MenuItem Foreground="Black" Header="Page3" Name="Page3" Click="Page3_Click"></MenuItem>
<MenuItem Foreground="Black" Header="Page4" Name="Page4" Click="Page4_Click"></MenuItem>
<Frame Name="mainFrame" NavigationUIVisibility="Hidden" ></Frame>
CODE BEHIND: Page1 loads when the application launches. Each Page Click event is setup like this
private void Page1_Click(object sender, RoutedEventArgs e)
{
mainFrame.NavigationService.Navigate(new Page1());
}
private void Page..._Click(object sender, RoutedEventArgs e)
{
mainFrame.NavigationService.Navigate(new Page...());
}
An example of what the issue is: If I open Page1, Page3, Page4, and then click the Frame's back button back to Page 1. At this point I open Page2. When I do this, every Page ahead on the Frame's (mainFrame) Navigation are closed (Page3 and Page4). I need to be able to Navigate to any screen (anywhere in the Navigation stack) without closing other Pages.
Upvotes: 0
Views: 296
Reputation: 1
I have tried using the old instances rather then new Page1(), however it still removes all Pages ahead of it in the stack when opening a new page. I can open Page1, Page3, Page4, but then I navigate back to Page 1 and try to Navigate to Page 2, Page3 and Page4 are still removed. Below is how i am getting to this issue:
1 - mainFrame.NavigationService.Navigate(new Page1());
2 - mainFrame.NavigationService.Navigate(new Page3());
3 - mainFrame.NavigationService.Navigate(new Page4());
4 - Navigate back to Page1 using the Back button 5 - Now I call mainFrame.NavigationService.Navigate(new Page2());, which then removes the Page3 and Page4
Upvotes: 0