-
Notifications
You must be signed in to change notification settings - Fork 802
Description
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
- 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>- Make sure
Itemsexists! I just made it a simpleIVector<String>
Expected behavior
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
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.

