Click here to Skip to main content
15,867,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to draw grid lines in Silverlight?
At present, I use Border objects to wrap all controls in the grid to display proper lines, like this:

XML
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="50"/>
        <ColumnDefinition Width="50"/>
        <ColumnDefinition Width="50"/>
    </Grid.ColumnDefinitions>

    <!--Row 0-->
    <Border Grid.Row="0" Grid.Column="0" BorderBrush="Black" BorderThickness="1">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="1"/>
    </Border>
    <Border Grid.Row="0" Grid.Column="1" BorderBrush="Black" BorderThickness="0,1,1,1">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="2"/>
    </Border>
    <Border Grid.Row="0" Grid.Column="2" BorderBrush="Black" BorderThickness="0,1,1,1">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="3"/>
    </Border>

    <!--Row 1-->
    <Border Grid.Row="1" Grid.Column="0" BorderBrush="Black" BorderThickness="1,0,1,1">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="4"/>
    </Border>
    <Border Grid.Row="1" Grid.Column="1" BorderBrush="Black" BorderThickness="0,0,1,1">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="5"/>
    </Border>
    <Border Grid.Row="1" Grid.Column="2" BorderBrush="Black" BorderThickness="0,0,1,1">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="6"/>
    </Border>

    <!--Row 2-->
    <Border Grid.Row="2" Grid.Column="0" BorderBrush="Black" BorderThickness="1,0,1,1">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="7"/>
    </Border>
    <Border Grid.Row="2" Grid.Column="1" BorderBrush="Black" BorderThickness="0,0,1,1">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="8"/>
    </Border>
    <Border Grid.Row="2" Grid.Column="2" BorderBrush="Black" BorderThickness="0,0,1,1">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="9"/>
    </Border>

</Grid>



Is there any simplier way to do that?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900