简体   繁体   中英

WPF Navigation Removes Prior Pages

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>
<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. I need to be able to Navigate to any screen without (anywhere in the Navigation stack) closing other Pages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM