Search code examples
xamlwindows-8.1winrt-xamlwindows-10windows-10-mobile

GridView Items Width


Got a GridView that its items width are set by the first one width(Screenshot)

How could I set some auto width for each item?

<GridView ItemsSource="{x:Bind PopularItems}" Style="{StaticResource GVStyle}" Height="230">
<GridView.ItemTemplate>
    <DataTemplate x:Name="GVTemp" x:DataType="models:LessDetails">
        <StackPanel>
            <Image Height="180" Width="132" Source="{x:Bind Img}" />
            <TextBlock Margin="4,4,0,4" HorizontalAlignment="Stretch" TextAlignment="Center"
       Text="{x:Bind Name}" Style="{ThemeResource BodyTextBlockStyle}" />
        </StackPanel>
    </DataTemplate>
</GridView.ItemTemplate>

Width of items set by the first item


Solution

  • You can not auto-width each item in a GridView control, it is by designed to use the first item's size as the uniform size (ListViewItemPresenter for each items has the same size).

    For the auto-size scenario, I suggest you using the StackPanel or creating a custom ItemsControl.