Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListView with inner Grid does not respect ColumnDefinition width on Windows 10 #10300

Closed
carlos-zamora opened this issue Jan 14, 2025 · 1 comment
Labels
area-Lists ListView, GridView, ListBox, etc bug Something isn't working product-winui2

Comments

@carlos-zamora
Copy link
Member

carlos-zamora commented Jan 14, 2025

Describe the bug

On Windows 10, if I have the following setup, the grid's column definitions aren't respected:

<ListView ItemsSource="{x:Bind Items}" Width="300">
    <ListView.ItemTemplate>
        <DataTemplate x:DataType="x:String">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{x:Bind}" VerticalAlignment="Center"/>
                <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button Content="Btn"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Specifically, note the star-sizing on the ColumnDefinitions.

Steps to reproduce the bug

  1. Add the following code to your XAML
<ListView ItemsSource="{x:Bind Items}" Width="300">
    <ListView.ItemTemplate>
        <DataTemplate x:DataType="x:String">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{x:Bind}" VerticalAlignment="Center"/>
                <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button Content="Btn"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
  1. Make sure Items exists! I just made it a simple IVector<String>

Expected behavior

Image

Note: this image was taken on Windows 11, where the issue doesn't occur.

I also found that Grids on their own (not inside a ListView) are fine.

Screenshots

Image

It seems like the ColumnDefinition.Width is set to Auto regardless of the value I put in. I was hoping that setting HorizontalAlignment to Right would remedy the issue, but no luck.

NuGet package version

WinUI 2 - Microsoft.UI.Xaml 2.8.2
Microsoft.UI.Xaml 2.8.7-prerelease.241119001

Windows version

Windows 11 (22H2): Build 22621

Known workaround

I managed to work around this issue by setting the width of the first column to the max width used by my controls/app. Since the second column has to have enough space to be drawn, the first column just gets "clipped" appropriately.

@carlos-zamora carlos-zamora added the bug Something isn't working label Jan 14, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jan 14, 2025
@karkarl karkarl added area-Lists ListView, GridView, ListBox, etc product-winui2 and removed needs-triage Issue needs to be triaged by the area owners labels Jan 16, 2025
@karkarl
Copy link
Contributor

karkarl commented Jan 16, 2025

We are closing the issue as we are not servicing WInUI2 except for major regressions and business needs.

@karkarl karkarl closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Lists ListView, GridView, ListBox, etc bug Something isn't working product-winui2
Projects
None yet
Development

No branches or pull requests

2 participants