Windows 8 GridView Max Items (Based on Screen Size)

I am creating an app for Windows 8 (not 8.1).

I would like to show some content on the screen just like in the Windows Store app.

I am currently using a GridView, but another control can be used if needed.

I need the following:

On a small screen, the Windows store only shows 6 items in a category as follows:

6 items on small screen

Whereas on a larger screen, it displays 9 items like this:

enter image description here

I would like to add a similar implementation, but I don’t know how.

Do I only need to set 6 items as the source for the GridView when the screen is small and 9 when the screen is large? Or can the GridView automatically display only as many items that can be seen in three columns and "n" rows?

Here is some sample code for my GridView - I am using WrapGrid to limit the number of columns to 3

<Grid Name="MyGrid">
    <GridView Name="MyGridView">
        <GridView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="3" />
            </ItemsPanelTemplate>
        </GridView.ItemsPanel>
    <GridView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Image Source="{Binding Icon}" Margin="10" Stretch="Uniform" Width="150" Height="150" />
            </Grid>
        </DataTemplate>
    </GridView.ItemTemplate>
</GridView>

      

+3


source to share


1 answer


Maybe you can do the attached behavior and attach it to the ItemsWrapGrid. The behavior will listen for SizeChanged and automatically change the MaximumRowsOrColumns property based on the available space and the size of the items



0


source







All Articles