Silverlight MasterPages

Someone in silverlight forums was looking for master page kind of functionality. Here is one way to do it

<Grid x:Name=”LayoutRoot” Background=”White”>
            <RowDefinition Height=”50″></RowDefinition>
            <RowDefinition Height=”*”></RowDefinition>
            <RowDefinition Height=”50″></RowDefinition>           
        <StackPanel   Height=”50″ Grid.Row=”0″  Orientation=”Horizontal”>
            <Button  Click=”Button_Click” Height=”25″ Tag=”c1″ Content=”Content page 1″></Button>
            <Button Click=”Button_Click” Height=”25″ Tag=”c2″  Margin=”10,0,0,0″ Content=”Content page 2″></Button>
            <Button  Click=”Button_Click” Height=”25″ Tag=”c3″ Margin=”10,0,0,0″ Content=”Content page 3″></Button>
        <Grid Grid.Row=”1″ x:Name=”ContentArea”>
            <ContentControl x:Name=”Container”></ContentControl>
        <Canvas Grid.Row=”2″ Background=”MediumSlateBlue”>
            <TextBlock Text=”This is footer” Margin=”100,5,100,5″></TextBlock>

we define  a grid with 3 rows the center row will take up all the space between the header row and footer row(top and bottom), when we need to change the content we are going to load the content into the ContentControl in Row 1 of the grid

 private void Button_Click(object sender, RoutedEventArgs e)
            Button b = sender as Button;
            string loadContent = b.Tag.ToString();
            switch (loadContent)
                case “c1”:
                    this.Container.Content = new ContentPage1();
                case “c2”:
                    this.Container.Content = new ContentPage2();
                case “c3”:
                    this.Container.Content = new ContentPage3();


7 thoughts on “Silverlight MasterPages


    Error 1 The type or namespace name ‘ContentPage1’ could not be found (are you missing a using directive or an assembly reference?) D:\MasterSilverLight\MasterSilverLight\Page.xaml.cs 28 50 MasterSilverLight

    1. Hi,
      In the code behind it creates a new instance of the a UserControl called Content1,Content2,Content3.
      looks like your project doesnt have UserControls with those names

Leave a Reply

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

You are commenting using your 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 )


Connecting to %s