Use in XAML a Uniformgrid and enter the amount of columns you want (in this case they are 3 columns) in the field Columns.
<UniformGrid Name="gridImagens" Columns="3">
</UniformGrid>
Now in code C# create image controls whose source is the images you want to show on the grid and add these controls to the Uniformgrid children collection. (A good practice is to clear the Uniformgrid child list before uploading the images, to ensure that the images will not be duplicated).
private void CarregueListaDeImagens()
{
gridImagens.Children.Clear();
var arquivosDeImagem = Directory.GetFiles(@"C:\Users\Ulysses\Pictures\TesteUniformGrid");
foreach (var imagem in arquivosDeImagem)
{
var bitmap = new BitmapImage(new Uri(imagem));
var controleImagem = new Image();
controleImagem.Source = bitmap;
gridImagens.Children.Add(controleImagem);
}
}
Follows below the final result when loading 10 images. Images are loaded 3 by 3 on each line, leaving blank spaces at the end when the number of images loaded is not multiple of 3, according to what you specified in your question.
What you have so far?
– PauloHDSousa