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.
CodePudding user response:
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.