Windows Community Toolkit AdaptiveGridView incorrect behavior

123244 80 Reputation points
2025-01-24T13:00:01.3166667+00:00

Hi, has anyone had this problem when using AdaptiveGridView (Win UI platform). The elements do not want to expand to occupy the full width available for them in the row (I attach a photo). I'll leave you the code for setting the AdaptiveGridView so that you can see where the possible error is. If you know how to fix it, I will be glad to hear your suggestions.

Code Example:

<controls:AdaptiveGridView DesiredWidth="180"
                           ItemHeight="160"
                           StretchContentForSingleRow="True"
                           ItemsSource="{x:Bind GroupedViewSource.View, Mode=OneWay}">
    <GridView.ItemTemplate>
        <DataTemplate x:DataType="directory:IDirectoryItem">
            <Grid Padding="10,15"
                  Background="Yellow">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <FontIcon VerticalAlignment="Center"
                          HorizontalAlignment="Center"
                          FontSize="20"
                          Glyph="&#xE721;" />

                <TextBlock Grid.Row="1"
                           Text="{x:Bind Name}" />
            </Grid>
        </DataTemplate>
    </GridView.ItemTemplate>
</controls:AdaptiveGridView>

Result:
photo_2025-01-24_14-56-17
photo_2025-01-24_14-46-15

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
12,007 questions
Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,238 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,547 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 20,021 Reputation points Microsoft Vendor
    2025-01-27T06:49:24.59+00:00

    Hello,

    Welcome to Microsoft Q&A!

    I was able to reproduce the same behavior, and this unexpected behavior has been reported on Github before.

    According to the Announcing Windows Community Toolkit v8.0, Microsoft.Toolkit.Uwp.UI.Controls has been deprecated as it is legacy and is no longer maintained. AdaptiveGridView has not been moved to the new package(CommunityToolkit.WinUI.UI.*). You can open a discussion to garner support for future migration or to get information on contributing to migrate it for everyone.

    In the meantime, it is recommended to use ItemsRepeater as an alternative.

    Thank you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.