Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF NavigationService.Navigate not showing up in Expression Blend

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?

Image Here

like image 400
nishantvodoo Avatar asked Feb 16 '23 06:02

nishantvodoo


1 Answers

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));
like image 169
Jasti Avatar answered Feb 18 '23 18:02

Jasti