简体   繁体   中英

Windows Template Studio WPF Navigation

I have a simple WPF app (code-behind) and would like to navigate from one view to another in code-behind.

In UWP, I could do this

NavigationService.Navigate(typeof(destinationView), "myParam");

since the NavigationService was a public static class.

Could someone explain how this can be done with the WPF project?

Template Studio Settings

<genTemplate:Item Name="generator" Value="Template Studio"/>
<genTemplate:Item Name="wizardVersion" Version="v5.1" />
<genTemplate:Item Name="projectType" Value="SplitView" />
<genTemplate:Item Name="framework" Value="CodeBehind" />
<genTemplate:Item Name="platform" Value="Wpf" />

Thank you.

Could someone explain how this can be done with the WPF project?

Just inject your view(s) with an INavigationService :

public partial class SomePage : Page
{
    private readonly INavigationService _navigationService
    public MainPage(INavigationService navigationService)
    {
        InitializeComponent();
        _navigationService = navigationService;
    }
    ...
}

Look at the generated MainPage.xaml.cs class for yet an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM