April 21, 2015 08:08 by
Peter
Navigation Framework is absolutely good however in some cases we have a tendency to don't need to use the Navigation Framework. This navigation technique may be used instead that 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);
}
Now, Edit 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. equally produce a button within the MainPage.xaml as well inorder to navigate to the NewPage. within 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 this 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 also the NewPage.xaml.
Silverlight 6 with Free ASP.NET Hosting
Try our Silverlight 6 with Free ASP.NET Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc. You will not be charged a cent for trying our service. Once your trial period is complete, you decide whether you'd like to continue.