#497 – Use a UniformGrid to Make a Group of Buttons the Same Size
February 17, 2012 1 Comment
You can use a StackPanel to make its child elements the same size in one of its dimensions. This is harder to do in the other dimension.
The example below uses a StackPanel to contain some buttons. They end up the same height, but are still different widths.
You can make the buttons the same height and width using a UniformGrid instead of a StackPanel.
<UniformGrid DockPanel.Dock="Bottom" Margin="10" Rows="1" HorizontalAlignment="Right" VerticalAlignment="Bottom"> <Button Grid.Column="0" Content="No" FontSize="18" Margin="5" Padding="6,3"/> <Button Grid.Column="1" Content="Yes, Absolutely" Margin="5" Padding="6,3"/> <Button Grid.Column="2" Content="Maybe" Margin="5" Padding="6,3"/> </UniformGrid>
The UniformGrid will make sure that each cell is the same height and the same width. This is desirable because you then avoid having to set the button sizes manually.
Pingback: Dew Drop – February 17, 2012 (#1,268) | Alvin Ashcraft's Morning Dew