2

In a UWP app using Template 10 we have an Admin page. The Admin page has 2 pages within a frame, AdminSettings1 and AdminSettings2. We wish to navigate between AdminSettings1 and AdminSettings2 in the frame, however we find we get to the target page, but lose the containing page.

How do we navigate between pages within a frame using Template 10 MVVM without losing the containing page?

The XAML (abbreviated):

<SplitView Grid.Row="1" 
           x:Name="AdminSplitView" 
           IsPaneOpen="True"  
           DisplayMode="Inline">
    <SplitView.Pane>
        <Grid>
            <ListView SelectionMode="Single" 
                      Name="AdminListBox">
                <ListViewItem Name="AdminSettings1" 
                              IsSelected="True" 
                              Tapped="{x:Bind AdminViewModel.GoToAdminSettings1}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Settings1"/>
                    </StackPanel>
                </ListViewItem>
                <ListViewItem Name="AdminSettings2" 
                              Tapped="{x:Bind AdminViewModel.GoToJobformSettings2}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Settings2"/>
                    </StackPanel>
                </ListViewItem>
            </ListView>
        </Grid>
    </SplitView.Pane>
    <SplitView.Content>
        <Frame Name="AdminFrame" />
    </SplitView.Content>
</SplitView>        

We arrive at AdminPage like this

GoToAdmin() => NavigationService.Navigate(typeof(Views.AdminPage));

In AdminPageViewModel we navigate to AdminPage2 like this

public void GoToAdmin2() => NavigationService.Navigate(typeof(Views.AdminPage2)); but this loses the containing Admin page

I referred to T10 documentation for Other examples of calling Navigate. This option navigates to the page bot loses the containing page

// from inside any window
var nav = WindowWrapper.Current().NavigationServices.FirstOrDefault();
nav.Navigate(typeof(Views.AdminPage2));

I was unable test this example in the documentation as I do not understand where MyFrame comes from

// from/with a reference to a Frame
var nav = WindowWrapper.Current(MyFrame).NavigationServices.FirstOrDefault();
nav.Navigate(typeof(Views.DetailPage), this.Value);

How do we navigate between pages within a frame using Template 10 MVVM?

Vague
  • 2,198
  • 3
  • 18
  • 46

1 Answers1

0

You can use the page cache and use this solution: https://github.com/MyToolkit/MyToolkit/wiki/Paging-Overview from this question: WinRT/UWP Frame and Page caching: How to create new page instance on Navigate() and keep the page instance on GoBack()

this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
  • Thank you @Vladimir Bolshakov but I'm trying to use the Template 10 navigation service. – Vague Jul 13 '17 at 09:14