Description
Describe the solution you'd like
Two properties, RowSpacing
and ColumnSpacing
, added to UniformGrid
.
Describe alternatives you've considered
The current "solutions" to this issue are:
<!-- fake rows/columns -->
<Grid
ColumnDefinitions="*,6,*,6,*"
RowDefinitions="*,6,*">
<... Grid.Row="0" Grid.Column="0" />
<... Grid.Row="0" Grid.Column="2" />
<... Grid.Row="0" Grid.Column="4" />
<... Grid.Row="2" Grid.Column="0" />
<... Grid.Row="2" Grid.Column="2" />
<... Grid.Row="2" Grid.Column="4" />
</Grid>
<!-- clunky Margin values -->
<Grid
ColumnDefinitions="*,*,*"
RowDefinitions="*,*">
<... Grid.Row="0" Grid.Column="0" Margin="0,0,4,3" />
<... Grid.Row="0" Grid.Column="1" Margin="2,0,2,3" />
<... Grid.Row="0" Grid.Column="2" Margin="4,0,0,3" />
<... Grid.Row="1" Grid.Column="0" Margin="0,3,4,0" />
<... Grid.Row="1" Grid.Column="1" Margin="2,3,2,0" />
<... Grid.Row="1" Grid.Column="2" Margin="4,3,0,0" />
</Grid>
<!-- if only one row or column is needed -->
<!-- still has klunky Margin values -->
<UniformGrid Rows="2">
<... Margin="0,0,3,0" />
<... Margin="3,0,0,0" />
</UniformGrid>
<!-- content is not of uniform width -->
<StackPanel
Orientation="Horizontal"
Spacing="6">
<... />
<... />
<... />
</StackPanel>
All of these have downsides.
The first Grid
method requires adding fake spacing rows and columns that must be accounted for. The second Grid
method requires manually thinking about all the Thickness
properties and seeing if they add up correctly. Simply, all must have Left+Right
and Top+Bottom
be equal to each other while ensuring spacing isn't on the left of the zeroth column, right of the last, etc. Not scalable at all.
The UniformGrid
method is just a specialization of the second Grid
method, but with only one row or column. Less manual calculations, but still tedious. And finally, the StackPanel
method uses the built-in Spacing
property, but has the downside that the content is not uniform is width/height.
The StackPanel
method can he hacked to work by binding to neighboring elements' own Width
(such as Width="{Binding #NeighborElement.Width}"
), but that's clunky and requires the programmer to ensure #NeighborElement
is always the widest, which it might not be after, say, localization.
I propose a solution that would have this simple XAML:
<UniformGrid
Columns="3"
ColumnSpacing="6"
Rows="2"
RowSpacing="6">
<... />
<... />
<... />
<... />
<... />
<... />
</UniformGrid>
It should be obvious how this is superior to the other methods.