47

I'd like to set a bottom border on each row in the grid, but can only find how to put all 4 borders around each cell..

<Grid Height="174" HorizontalAlignment="Left" Margin="23,289,0,0" Name="grid2" VerticalAlignment="Top" Width="730">
    <Grid.RowDefinitions>
        <RowDefinition Height="45" />
        <RowDefinition Height="25" />
        <RowDefinition Height="25" />
        <RowDefinition Height="25" />
        <RowDefinition Height="25" />
        <RowDefinition Height="25" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="255" />
        <ColumnDefinition Width="95" />
        <ColumnDefinition Width="95" />
        <ColumnDefinition Width="95" />
        <ColumnDefinition Width="95" />
        <ColumnDefinition Width="95" />
    </Grid.ColumnDefinitions>
</Grid>

For another grid I'm using that needs all four borders, I'm using

<Border Grid.Column="0" Grid.Row="0" BorderBrush="#61738B" BorderThickness="1" />

P.S. The contents of the grid are some labels, textboxes, etc.. if that matters at all.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Marko
  • 71,361
  • 28
  • 124
  • 158

2 Answers2

119

On a Border control You can do BorderThickness="0 0 0 1" to only have a bottom border shown.

Top and bottom border thickness of 5, left and right border thickness of 0

BorderThickness="0 5"

Top and bottom border thickness of 0, left and right border thickness of 5

BorderThickness="5 0"

Border Thickness - Left: 1, Top: 2, Right:3, Bottom: 4

BorderThickness="1 2 3 4"

starball
  • 20,030
  • 7
  • 43
  • 238
Mark Carpenter
  • 17,445
  • 22
  • 96
  • 149
  • oh lord, it was that simple? Thanks a million! Another quick question - is there a way I can set the border on the entire row, without having to specify Grid.Column? – Marko Sep 12 '10 at 05:12
  • 1
    No problem! To my knowledge, I don't know if you can define a Row's border in the RowDefinition. If you're talking about having your border in a particular row span multiple columns, you can use Grid.ColumnSpan. Not sure if that's what you mean, but hope it helps. – Mark Carpenter Sep 12 '10 at 05:18
  • Thanks @Pwninstein Grid.ColumnSpan helps, it places a border across each of column, now I've just gotta figure out how to have it repeat on each row without having 6 different declarations :) – Marko Sep 12 '10 at 09:27
  • Yeah... if it were me writing it, I'd probably just end up having 6 different `Border`s, I don't know of a way to do that either (I'd be glad to hear a way if someone knows one!) – Mark Carpenter Sep 12 '10 at 13:13
  • Thank you very much! I also was looking for that. – Alexander Prokofyev Sep 21 '11 at 10:13
  • I've set HorizontalAlignment=Right and those borders painted only for text lenght, if I remove this the borders are fine. – digz6666 Aug 22 '13 at 09:02
0

I had luck putting a bottom border on a whole row by including a Border Node with BorderThickness="0 1 0 1" surrounding the Grid Node. Like this:

Border Style="{StaticResource ItemBorderStyle}" BorderThickness="0 1 0 1"
            Grid Style="{StaticResource GridItemStyle}"
sra
  • 23,820
  • 7
  • 55
  • 89
Lion8
  • 19
  • 2