Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you layout buttons in a table format?

Tags:

c#

wpf

How would you approach making a "table" filled with buttons?

Ex. (b=button control)

b b b b b

b b b b b

b b b b b

b b b b b

I understand how to generally use Dock and Stack Panels. Would I have to make a nested group of stack panels where I make 5 vertical stack panels and then place them in a horizontal stack panel? or is there an easier way?

like image 464
meisenman Avatar asked Nov 23 '25 08:11

meisenman


2 Answers

<UniformGrid Rows="5" Columns="5">
   <!-- your buttons -->
</UniformGrid>

You can learn about the UniformGrid at MSDN.

Constraining the Rows is optional, if you may have more than exactly 25 buttons.

If you do not necessarily want all the cells of the grid to have equal size, then you can lay out a standard Grid. The drawback to that is that declaring the ColumnDefinitions and RowDefinitions properties is verbose.

like image 143
Jay Avatar answered Nov 26 '25 00:11

Jay


If you dont mind the buttons being evenly spaced you could use

<UniformGrid Columns="5">
    <Button />
    ...
    <Button />
</UniformGrid>
like image 38
ghord Avatar answered Nov 26 '25 01:11

ghord