Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative margins does not behave as expected when there's a size constraint #18124

Open
appel1 opened this issue Feb 5, 2025 · 0 comments
Open
Labels

Comments

@appel1
Copy link
Contributor

appel1 commented Feb 5, 2025

Describe the bug

I think the issue is that when there's a size constraint, MaxWidth in my example, the desired size is constrained before inflating the result with the margin in Layoutable.MeasureCore. So the desired size ends up being 100 - 20 = 80 instead of 100.

If there's a StackPanel that lets its children be as wide as they desire this also results in the text block drawing outside of its containing control.

To Reproduce

Create a new desktop app and paste the following into the Window in MainWindow.xaml.

  <Canvas>

    <Border Canvas.Top="100" Canvas.Left="100" MaxWidth="100" Background="#8800ff00">
      <Border Background="#88ff0000" Margin="-10">
        <StackPanel Orientation="Vertical">
          <TextBlock Text="Lorem ipsum dolor sit amet" Margin="10" TextTrimming="CharacterEllipsis"/>
        </StackPanel>
      </Border>
    </Border>

    <Border Canvas.Top="150" Canvas.Left="100" MaxWidth="100" Background="#8800ff00">
      <Border Background="#88ff0000" Margin="-10">
        <TextBlock Text="Lorem ipsum dolor sit amet" Margin="10" TextTrimming="CharacterEllipsis"/>
      </Border>
    </Border>
    
    <Border Canvas.Top="200" Canvas.Left="100" MaxWidth="100" Background="#8800ff00">
      <Border Background="#88ff0000">
        <StackPanel Orientation="Vertical">
          <TextBlock Text="Lorem ipsum dolor sit amet" TextTrimming="CharacterEllipsis"/>
        </StackPanel>
      </Border>
    </Border>

  </Canvas>

This results in the following:
Image

Expected behavior

The expected behavior is for all of the outer Border elements to have the same width, ~100, and for all the text blocks with orange background to have the same width, ~100, and that the text should not be drawn outside of the orange rectangle.

The bottom most one is the one with the correct width.

Avalonia version

11.2.3

OS

Windows

Additional context

No response

@appel1 appel1 added the bug label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant