Navigation Framework is really good but in some cases we do not want to use the Navigation Framework. This navigation technique can be used instead which provides simple Navigation. Add the following code in App.xaml: private static Grid root; public static void Navigate(UserControl newPage) { UserControl oldPage = root.Children[0] as UserControl; root.Children.Add(newPage); root.Children.Remove(oldPage); } Modify the App.xaml as shown below: Previous code: private void Application_Startup(object sender, StartupEventArgs e) { this.RootVisual = new MainPage(); } Modified code: private void Application_Startup(object sender, StartupEventArgs e) { root = new Grid(); root.Children.Add(new MainPage()); this.RootVisual = root; } Create a new usercontrol NewPage . Add Button to the Page inorder to navigate to the Home. Similarly create a button in the MainPage.xaml as well inorder to navigate to the NewPage. In the Button Click event add the following code ; App app = (App)Application.Current; App.Navigate(new NewPage()); Application.Current gets the System.Windows.Application object for the current application. The new instance of the Page is passed to the Navigate method of App class. When we run the code we are able to navigate between the MainPage and the NewPage.xaml.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: