I have a problem with the navigation of Frame in UWP.
I have a frame (Frame 1) defined in MainPage.xaml and only one page (Page 1) will be loaded by this frame. Page 1 also has a frame (called SubPageFrame, collapsed) and some other contents (BasicContent, visible). SubPageFrame could navigate pages by this order:
Page 1-1 -> Page 1-2 -> Page 1-3 -> ... -> GoBack() -> ... -> Page 1-1
Here is the part of XAML:
<!-- This Grid is contained in Page 1. -->
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ScrollViewer Name="BasicContentScrollViewer" VerticalScrollBarVisibility="Auto">
<!-- BasicContent -->
</ScrollViewer>
<Frame Name="SubPageFrame" Visibility="Collapsed">
<!--Page 1-x will be loaded here-->
</Frame>
</Grid>
When I navigate to Page 1-1, I will collapse the ScrollViewer and display SubPageFrame. When I return to the Page 1-1 I loaded firstly, obviously I can't use SubPageFrame.GoBack() to get BasicContent. So I use the property CanGoBack
to check the BackStack
when I want to display BasicContent:
if(SubPageFrame.CanGoBack == false)
{
//collapse SubPageFrame
//display ScrollViewer
}
But this operation means Page 1-1 still be kept in SubPageFrame. When I use SubPageFrame again, its BackStack
will contains Page 1-1 and the new Page. It can be predicted that every time I want to return to BasicContent I must go back to Page 1-1 whether or not I have called Page 1-1.
I have two steps to test my code and here is a picture to describe the two steps: here.
After step 1, I still get Page 1-1 in step 2, which is not what I expect.
My problem is when I go back to Page 1-1, I can make BasicContent visible (it's OK) and make SubPageFrame return to its initial state (the frame doesn't contain any page).
I can't find any method to do it.
How can I clear a BackStack of a Frame? The first page navigated by SubPageFrame does not seem to be removed by SubPageFrame.BackStack.Clear()
.
Or is there a better solution for my code?