I am trying to create a WPF application but I cannot navigate to a custom xaml file on a button click event. I am importing the navigation service method but for some reason the "NavigationService.Navigate" is not showing up. It only shows me NavigationService.GetNavigationService. Can anyone give me an idea what the issue might be?
NavigationService.Navigate is part of Page object. If you inherit your XAML from
public partial class MainWindow : Page
instead of
public partial class MainWindow : Window
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>
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>
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With