Skip to content

Grid calculated actual size bug (child element margins not used correctly) #18607

Closed

Description

@mikernet

Current behavior

Grids set their actual size incorrectly with respect to child elements with margins. We use the following code in ContentDialog to force the content to take up as much room as possible, up to a desired max width/height:

<ContentDialog
  x:Class="Volt.Views.Tracking.SelectLocationDialog"
 ...>

  <Grid CornerRadius="8" MaxWidth="600" MaxHeight="600">
    <!-- Forces the grid to try to stretch to the max width and height above if the room is available,
            but the actual grid width/height should not exceed the available width/height in the
            content dialog -->
    <Rectangle x:Name="PushRect" Width="600" Margin="0,0,0,9999"/>

    <maps:MapControl x:Name="MapView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
  </Grid>
</ContentDialog>

This works fine in WinUI, but in Uno the grid's actual height gets set to 9999 instead of filling the available height in the content dialog, which means that in the example above, the map height now stretches to 9999 as well instead of the available height in the content dialog.

This is how it should behave:

Recording.2024-10-28.122051.mp4

Expected behavior

The bottom 9999 margin of PushRect should not cause the grid's actual size to go beyond the available height in the grid's parent container.

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

Yes

Environment

Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

5.4.10

Affected platforms

WebAssembly, Android, iOS, Mac Catalyst, Skia (WPF), Skia (Linux X11), Skia (macOS), Skia (Linux Framebuffer), Skia (GTK), Windows (WinAppSDK)

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

Activity

  1. added
    difficulty/tbd
    kind/bug
    triage/untriaged
    on Oct 28, 2024
  2. changed the title [-]Grid sizing bug[/-] [+]Grid calculated actual size bug (child element margins not used correctly)[/+] on Oct 28, 2024
  3. added
    project/layout 🧱
    difficulty/medium 🤔
    and removed
    triage/untriaged
    difficulty/tbd
    on Oct 29, 2024
  4. added theissue type on Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

difficulty/medium 🤔kind/bugproject/layout 🧱

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions