tags:

views:

76

answers:

1

Hello,

I am currently using Silverlight 3. I want to create the equivalent of a 2x2 HTML table. I want each cell to have a black border. How do I do this in Silverlight? Isn't there a property I can set on a Grid element to make each cell have a border?

Thank you,

+1  A: 

Nope. Grid is simply one of a number of panel types that are designed to layout their children in specific way. Grids are used extensively in many different and often nested ways. They are lightweight and therefore do not carry loads of baggage that may or may not get used, such as in this a bunch of properties to determine borders on "cells".

To create a border on each cell simply use the Border control:-

<Grid>
  <Grid.Resources>
    <Style x:Key="borderStyle" TargetType="Border">
      <Setter Property="BorderBrush" Value="Black" />
      <Setter Property="BorderThickness" Value="1" />
      <Setter Property="Padding" Value="2" />
    </Style>
  </Grid.Resource>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>
  <Border Style="{StaticResource borderStyle}" Grid.Row="0" Grid.Column="0">
    <!-- Cell 0.0 content here -->
  </Border>
  <Border Style="{StaticResource borderStyle}" Grid.Row="0" Grid.Column="1">
    <!-- Cell 0.1 content here -->
  </Border>
  <Border Style="{StaticResource borderStyle}" Grid.Row="1" Grid.Column="0">
    <!-- Cell 1.0 content here -->
  </Border>
  <Border Style="{StaticResource borderStyle}" Grid.Row="1" Grid.Column="1">
    <!-- Cell 1.1 content here -->
  </Border>
</Grid>
AnthonyWJones