Describe the bug
When Windows constrains the initial window size, children inside a Grid can remain arranged at the originally requested width.
The native client size, Avalonia ClientSize and root Grid bounds already reflect the smaller size, but a right-aligned button extends beyond the window's right edge.
The incorrect layout persists after pending dispatcher work has completed. Manually resizing the window, or maximizing and restoring it, corrects the layout.
This reproduces with standard Avalonia controls: a Window containing a Grid, a Button and an empty DataGrid. No application-specific controls or view models are required.
To Reproduce
- Create a desktop application using Avalonia 12.1.1, Avalonia.Controls.DataGrid 12.1.2 and the Fluent theme.
- Include the DataGrid Fluent styles in Application.Styles:
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
- On Windows with a 1920 × 1080 display at 100% scaling, set the main window's Width to 2034, Height to 900, MinWidth to 960 and MinHeight to 650.
- Use this window content:
<Grid Margin="10" RowDefinitions="Auto,*">
<Border Padding="8">
<Button HorizontalAlignment="Right">
Shell integration…
</Button>
</Border>
<DataGrid Grid.Row="1" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Message" Width="*" />
</DataGrid.Columns>
</DataGrid>
</Grid>
- Start the application without resizing or maximizing the window.
- Inspect the right-aligned button. If necessary, move the window to expose its right border without changing its size. The button is clipped inside the window frame.
- Resize the window or maximize and restore it. The layout becomes correct.
On a different display, request a width larger than the display's logical width so that Windows constrains the initial window size.
Expected behavior
The content should be arranged within the actual client area when the window first opens. A right-aligned button should be fully visible without requiring a manual resize or maximize-and-restore.
Avalonia version
12.1.1
OS
No response
Additional context
Environment:
- Windows 11
- .NET 10
- Avalonia 12.1.1
- Avalonia.Controls.DataGrid 12.1.2
- Fluent theme
- Display: 1920 × 1080, 100% scaling
Measured immediately after opening, without a subsequent resize:
| Measurement |
Width |
| Requested window width |
2034 |
| Native client area |
1924 |
| Avalonia ClientSize |
1924 |
| Root Grid |
1904 |
| First-row Border |
2014 |
The root Grid correctly accounts for its margins, but the first-row Border retains the larger width.
Workaround: running the following in the window's Opened handler corrects the layout immediately:
if (Content is Control content)
{
content.InvalidateArrange();
UpdateLayout();
}
UpdateLayout() alone does not fix the issue.
Related: #16548 and its fix #18338. This reproduction concerns OS size constraints during the initial Show(), rather than changing Width after the window has opened. It still reproduces in 12.1.1.
Our investigation suggests that the content is remeasured after the size correction, but the required rearrangement can be skipped. This is a suspected explanation, not a confirmed upstream diagnosis.
Describe the bug
When Windows constrains the initial window size, children inside a Grid can remain arranged at the originally requested width.
The native client size, Avalonia ClientSize and root Grid bounds already reflect the smaller size, but a right-aligned button extends beyond the window's right edge.
The incorrect layout persists after pending dispatcher work has completed. Manually resizing the window, or maximizing and restoring it, corrects the layout.
This reproduces with standard Avalonia controls: a Window containing a Grid, a Button and an empty DataGrid. No application-specific controls or view models are required.
To Reproduce
On a different display, request a width larger than the display's logical width so that Windows constrains the initial window size.
Expected behavior
The content should be arranged within the actual client area when the window first opens. A right-aligned button should be fully visible without requiring a manual resize or maximize-and-restore.
Avalonia version
12.1.1
OS
No response
Additional context
Environment:
Measured immediately after opening, without a subsequent resize:
The root Grid correctly accounts for its margins, but the first-row Border retains the larger width.
Workaround: running the following in the window's Opened handler corrects the layout immediately:
UpdateLayout() alone does not fix the issue.
Related: #16548 and its fix #18338. This reproduction concerns OS size constraints during the initial Show(), rather than changing Width after the window has opened. It still reproduces in 12.1.1.
Our investigation suggests that the content is remeasured after the size correction, but the required rearrangement can be skipped. This is a suspected explanation, not a confirmed upstream diagnosis.