开发者

How to create a bordered table in Silverlight?

I am currently using Silverli开发者_Go百科ght 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?


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.Resources>
  <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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜