.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Simple Navigation in silverlight

Posted By:Mahadesh Mahalingappa       Posted Date: August 17, 2011    Points: 200    Category: Silverlight    URL: http://www.dotnetspark.com  

In this article we are going to see how we can navigate between pages without using the Navigation Framework in Silverlight
 

In this article we are going to see how we can navigate between pages without using the Navigation Framework .

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 .
 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend