One of the least used layout panels in WPF is the UniformGrid. Perhaps it is because it is so simple it gets overlooked when choosing a layout container. Essentially, a UniformGrid creates a mesh of equally sized cells. You have no direct control over the size of the cells, you specify the number of rows and columns and the panel does the rest. You can think of it as a simplified Grid.
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
As you can see, the location of each child of the UniformGrid is in the order they are added in the XAML.
What happens if you put more children in the UnformGrid then you have cells defined? Interestingly, the panel will still load the children. In the next example there are nine cells and ten children. The margin of the UniformGrid has been modified so that we can see more of the its content.
The following code determines what element is the parent for the 10th button. It proves that the button is a child of the UniformGrid.
Using the UniformGrid in an ItemsPanelTemplate
Naturally you can use a UniformGrid in an ItemsPanelTemplate. This makes it simple to create uniform sized grids of data.
In the following screen shot you can see the penguin image is selected in the ListBox and that the UniformGrid is arranging the items as expected.