I would like to fill the space available in the GridView control with images. In specific, I would like to make 4 columns, each column with an Image. No space between columns.
First thought: GridView fills the whole space available in the page, so I just need a converter that binds to the ActualWidth property of the GridView and than divide it by four (columns). This should give me four columns with the same Width. The problem is that unfortunatly Width is not a simple number and dividing by 4 it gives probably a not perfect number, so the sum of the 4 columns Width can go over the grid and the result is that I can see only three columns instead of four. Even if I set the margin and the padding to zero, the result does'nt change. The code is the following:
<GridView x:Name="Photos">
<GridView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Url}"
Width="{Binding ElementName=Photos, Path=ActualWidth, Converter={StaticResource DivideByFourConverter}}"
Height="{Binding ElementName=Photos, Path=ActualWidth, Converter={StaticResource DivideByFourConverter}}
Stretch="UniformToFill" />
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
Second thought: try to not set the Width and Height on the Image, but make a WrapGrid setting the maximum number of rows and columns. Nothing, I see the same result....
<GridView x:Name="Photos">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid MaximumRowsOrColumns="4"
Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Url}"
Stretch="UniformToFill" />
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
Just to be clear, here is the screen: https://i.stack.imgur.com/SL7QP.png
Isn't it possible to have a simple grid with items filling it without margins? The Platform is Windows Phone 8.1 RT so no possibility of using GridViewColumns.
I was even thinking of doing a hidden Grid with 4 columns with * sizing and binding the Image to the Width of a column but... I was searching for a smarter solution :)