Skip to content

Windows: Grid children remain too wide when the initial window size is constrained by the OS #22283

Description

@trivalik

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

  1. Create a desktop application using Avalonia 12.1.1, Avalonia.Controls.DataGrid 12.1.2 and the Fluent theme.
  2. Include the DataGrid Fluent styles in Application.Styles:
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
  1. 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.
  2. 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>
  1. Start the application without resizing or maximizing the window.
  2. 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.
  3. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions