如何在Silverlight中创建带边框的表格?

3

我目前正在使用Silverlight 3。 我想创建一个等同于2x2的HTML表格。 我希望每个单元格都有黑色边框。 在Silverlight中如何实现这一点? 是否可以在Grid元素上设置属性以使每个单元格都有边框?

1个回答

4
不是的。网格(Grid)只是设计用于特定排列其子元素的众多面板类型之一。网格在许多不同的嵌套方式中被广泛使用。它们很轻量级,因此不会携带可能或者可能不会使用的大量负担,例如在“单元格”上确定边框的一堆属性。
要在每个单元格上创建边框,只需使用Border控件:
<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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接