How can I navigate to back frame in uwp app? I have a frame and it loads three pages in that frame. So when I click on back button I need to see the previous page loaded in that frame. Please help. In the code I need to get the page loaded in the Mainframe
<Image Source="/Assets/Images/PURlogo_large.png" HorizontalAlignment="Left" Margin="70,950" Width="212" Height="78"/>
</Grid>
</StackPanel>
<Frame x:Name="MainFrame" Grid.Column="1" Content="{Binding FrameData,Mode=OneWay}" >
</Frame>
<Grid Background="Red" Visibility="Collapsed" x:Name="testgrid">
<TextBlock Text="hello world"></TextBlock>
</Grid>
</Grid>
In App.xaml.cs : I have a common method to handle the back button.
private bool On_BackRequested()
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame.Content is HomeView homeview)
{
// here I do nothing as it is handled by the back method in homeview.xaml.cs
}
if (rootFrame.Content is MyPageView myPage)
{
if (rootFrame.CanGoBack)
{
//Here its going back to the page instead of the frame.
}
}
else if (rootFrame.CanGoBack)
{
rootFrame.GoBack();
return true;
}
return false;
}
this is in the homeview.xaml.cs where the frame is located. This works fine.
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
if (MainFrame.CanGoBack)
{
e.Handled = true;
MainFrame.GoBack();
}
}
my navigation is like this. page1->page2(contains frame)->framepage 1->framepage2->page 3
Once I click back from page 3 instead of going to page 2 second frame page(framepage2) it goes to page 2 with first frame page. So how to fix that using a common method as the one above in app.xaml.cs