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());

🙂

2 thoughts on “How to redirect the XAML file in silverlight

  1. Jeremy May 20, 2011 at 6:11 pm Reply

    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. kethare May 28, 2011 at 7:56 am Reply

    root is an object of ‘Grid’ Container control.

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 )

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: