UseLayoutRounding with GridUnitType.Auto causing unexpected gaps on collapsed Grids
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: Tested on 4.8 net5.0 and net6.0
* Windows version: Tested on windows 10
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
**Problem description:**
Setting UseLayoutRounding to true when using grids with GridUnitType.Auto results in a collapsed grid's height being approx 1px
**Actual behavior:**
Unexpected gaps between visible grids.

**Expected behavior:**
No gaps to appear.
**Noticed**
On my development machine.
Without UseLayoutRounding the Grids actual heights are 15.xxx but when using LayoutRounding it's rounded off to 17,
When I would have expected 16.
Adding an extra unused RowDefinition with GridUnitType.Star seems to fix the problem.
The heights are 16 as I would expect.
There are no unexpected gaps.
While this is a potential workaround for us, it's not ideal.
**Minimal repro:**
Default WPF application.
Name root grid element to layoutroot
Using code behind for simplicity vs XAML directly (Issue seen in both)
this.UseLayoutRounding = true;
for (int i = 0; i < 15; i++)
{
var rowdefinition = new RowDefinition()
{
Height = new GridLength(1, GridUnitType.Auto)
};
this.layoutroot.RowDefinitions.Add(rowdefinition);
var grid = new Grid();
var textBlock = new TextBlock()
{
Text = "Test"
};
grid.Children.Add(textBlock);
grid.Background = new SolidColorBrush(Colors.Red);
Grid.SetRow(grid, i);
if (i % 3 == 0)
{
grid.Visibility = Visibility.Collapsed;
}
this.layoutroot.Children.Add(grid);
}
Contributor guide
Assessment
This issue has not been assessed yet.