I'm making a simple memory game, but for some reason I can't get the cards to not spread out like in the image. I put the cards in a grid that I put in the middle of a 3-column grid like this:
xaml:
<Grid x:Name="mainGrid">
<Image x:Name="bgImage" Aspect="AspectFill"/>
<Grid x:Name="innerGrid" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
</Grid>
cs:
Grid gr = new Grid
{
ColumnSpacing = 0,
RowSpacing = 0,
};
for (var i = 0; i < numRows; i++)
{
gr.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
}
for (var i = 0; i < numCols; i++)
{
gr.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
}
innerGrid.Children.Add(gr, 1,0);
var rowCount = 0;
var colCount = 0;
for (var i = 0; i < bricks.Count; i++)
{
Image img = new Image
{
Source = Globals.mediaUrl + bricks[i].img,
ClassId = bricks[i].img,
Margin = new Thickness(0, 0, 0, 0)
};
gr.Children.Add(img,colCount,rowCount);
colCount++;
if (colCount > numCols - 1)
{
colCount = 0;
rowCount++;
}
}
But for some reason I don't understand the cards spread out anyway like in this picture:
Can someone please help me with this





