Home > Silverlight > How to redirect the XAML file in silverlight

How to redirect the XAML file in silverlight

Here is the code to redirect with in silverlight(XAML) file .

public static void Navigate(UserControl newPage)        {

            UserControl oldPage = root.Children[0] as UserControl;

            root.Children.Add(newPage);

            root.Children.Remove(oldPage);

        }

Add the above method in App.xaml file . Then modify the Application_Startup method as below code.

private void Application_Startup(object sender, StartupEventArgs e)        {

            root = new Grid();

            root.Children.Add(new MainPage());

            this.RootVisual =root;

        }

Then you can add the below code line in the page as want for example you can put it inside the button click event

App.Navigate(new MarketCenter());

🙂

Advertisements
Categories: Silverlight
  1. Jeremy
    May 20, 2011 at 6:11 pm

    Hi,

    private void Application_Startup(object sender, StartupEventArgs e) {

    root = new Grid();

    root.Children.Add(new MainPage());

    this.RootVisual =root;

    }

    May i ask what datatype root is?

  2. May 28, 2011 at 7:56 am

    root is an object of ‘Grid’ Container control.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: