Question

I have a UserControl that contains a Frame with a UriMapper. This is also my RootVisual, so it is what is loaded when the application is loaded. This is my (simplified) XAML:

<UserControl>
    <navigation:Frame x:Name="ContentFrame" Source="/Page1">
        <navigation:Frame.UriMapper>
            <uriMapper:UriMapper>
                <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
                <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
            </uriMapper:UriMapper>
        </navigation:Frame.UriMapper>
    </navigation:Frame>

<HyperlinkButton x:Name="Page1Link" NavigateUri="/Page1" TargetName="ContentFrame" Content="Page1"/>
<HyperlinkButton x:Name="Page2Link" NavigateUri="/Page2" TargetName="ContentFrame" Content="Page2"/>
</UserControl>

This all works great, but now I want to add a back-button. When the user clicks the button, I want to call

NavigationService.GoBack();

I can call the NavigationService from the pages (Page1 and Page2), but how can I call the NavigationService from this 'parent' UserControl? Is it possible? In this UserControl, the NavigationService is always null.

I would either want to access the NavigationService from the pages shown in the Frame, or pass the button click event to these pages.

I don't want to have to put a button in each Page and handle the navigation there.

Was it helpful?

Solution

Try using

ContentFrame.Navigate(YOUR_URI);

and

ContentFrame.GoBack();

in your parent UserControl that contains the navigation frame with x:Name="ContentFrame".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top