Because the total width of my grid divided by four (columns) isn’t a round number, the grid isn’t a perfect grid as seen at the bottom. Is there a way to force the width of the grid to be dividable by 4 so the grid is always perfect?
preferably by keeping width dynamic without setting width in points.
You should get rid of the StackPanel and just let Grid do its job in how it’s sizing and filling its cells. Also, it seems that you could just set the box-aspect right on the Grid, too?
Here’s a complete example that doesn’t suffer from any aliasing:
I’m not sure what’s the cause of the not-perfect-square, but changing the Aspect property value (below 1, over 1) squashes it either vertically or horizontally.
The Aspect="#" is a ratio of the desired X to Y aspect. If you want square cells this number needs to be the ratio of horizontal to vertical cells. For example:
<Grid ColumnCount="4" RowCount="3" Aspect="4/3">
or
<Grid ColumnCount="3" RowCount="7" Aspect="3/7"/>
These will result in square cells. You then use Row,Column,RowSpan and ColumnSpan to fill up those cells with images.
I think you’re desired grid, the last image you posted, might be:
<Grid ColumnCount="4" RowCount="5" Aspect="4/5">
Most images will just fill one cell, but the large ones will be <Image Row="0" Column="0" RowSpan="2" ColumnSpan="2"> and <Image Row="2" Column="1" RowSpan="3" ColumnSpan="3"/>