nis*_*doo 3 wpf uinavigationcontroller
我正在尝试创建一个WPF应用程序,但我无法导航到按钮单击事件上的自定义xaml文件.我正在导入导航服务方法但由于某种原因导致"NavigationService.Navigate"没有显示.它只显示了NavigationService.GetNavigationService.谁能让我知道问题可能是什么?

NavigationService.Navigate is part of Page object. If you inherit your XAML from
public partial class MainWindow : Page
Run Code Online (Sandbox Code Playgroud)
instead of
public partial class MainWindow : Window
Run Code Online (Sandbox Code Playgroud)
If you want to navigate to a page from main window create a frame in mainwindow as below
<DockPanel>
<Frame x:Name="_NavigationFrame" NavigationUIVisibility="Hidden" />
</DockPanel>
Run Code Online (Sandbox Code Playgroud)
and then in your mainwindow constructor call
_NavigationFrame.Navigate(new CustomXml());
EDIT:
Sorry for the confusion CustomXaml is just the name of CustomPage.
I will use the following design for page navigation application
Steps 1: Create MainWindow.Xaml and add the following Code
<DockPanel>
<Frame x:Name="_NavigationFrame" NavigationUIVisibility="Hidden" />
</DockPanel>
Run Code Online (Sandbox Code Playgroud)
Frame is a placeholder for all the pages.
Step 2: Create a main page MainPage.xaml (like home page) and place all the code you intend to place in MainWindow.XAML into this MainPage.XAML. To open this main page on application load add the following code in MainWindow.Xaml constructor
_NavigationFrame.Navigate(new MainPage());
where MainPage() is the constructor of MainPage.XAML
Step 3: Create a custom Page CustomPage.XAML (the page you want to navigate to). In order to navigate to this page from first page
this.NavigationService.Navigate(new Uri("CustomPage.xaml", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)