Search code examples
c#uwpuwp-xamluwp-navigation

UWP NavigationView prevent unload Pages


I'm using a NavigationView and when I navigate to a different page the previous one is unload, this is OK for some pages (and should be that way), but for other pages I wanted to maintain the Page loaded even if I navigate away from that Page.

Is this Possible?

The code for NavigationView

<NavigationView x:Name="NavigationView"
                MenuItemsSource="{x:Bind ViewModel.Items}"
                MenuItemTemplate="{StaticResource NavigationViewItem}"
                SelectedItem="{x:Bind ViewModel.SelectedItem, Mode=TwoWay}"
                SelectionChanged="OnSelectionChanged">

    <Grid>
        <Frame x:Name="frame">
            <Frame.ContentTransitions>
                <TransitionCollection>
                    <NavigationThemeTransition/>
                </TransitionCollection>
            </Frame.ContentTransitions>
        </Frame>
    </Grid>
    <NavigationView.PaneFooter>
        <NavigationViewItem ContentTemplate="{StaticResource NavigationViewItemProfile}"
                            Content="{x:Bind ViewModel.UserInfo}"/>
    </NavigationView.PaneFooter>

</NavigationView>

Solution

  • Set page's NavigationCacheMode to NavigationCacheMode.Required in its constructor or XAML declaration.