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

Use size enforced by Width/Height for content measurements #984

Closed
wants to merge 1 commit into from

Conversation

kekekeks
Copy link
Member

If Size is being enforced by Width/Height, contents are still measured with availableSize.

Minimal code to reproduce the issue:

<Window xmlns="https://github.com/avaloniaui" Title="Test app" WindowState="Maximized" MinWidth="500" MinHeight="300">
    <Button Content="Button text" Margin="40,65,0,0" Width="201" Height="65">
        <TextBlock>Button Text</TextBlock>
    </Button>
</Window>

I'm not sure that we should fix it this way, so no unit test for now

@kekekeks kekekeks requested a review from grokys May 15, 2017 16:52
@grokys
Copy link
Member

grokys commented May 23, 2017

This should already be handled by this line:

double width = (control.Width > 0) ? control.Width : constraints.Width;

I've written a unit test to test the behavior, and it passes:

        [Fact]
        public void Width_Should_Affect_AvailableSize()
        {
            MeasureTest target;

            var outer = new Decorator
            {
                Width = 100,
                Height = 100,
                Child = target = new MeasureTest
                {
                    Width = 70,
                }
            };

            outer.Measure(Size.Infinity);

            Assert.Equal(new Size(70, 100), target.AvailableSize);
        }

        class MeasureTest : Control
        {
            public Size? AvailableSize { get; private set; }

            protected override Size MeasureOverride(Size availableSize)
            {
                AvailableSize = availableSize;
                return availableSize;
            }
        }

In the example you gave, the width and height properties also seem to be getting applied correctly before MeasureOverride. Maybe your problem is the fact that the margin is applied after the layout constraints are applied?

It might help in this situation to write failing unit tests first, to give us an idea of what the problem might be.

@kekekeks
Copy link
Member Author

Fixed by #994

@kekekeks kekekeks closed this May 26, 2017
@grokys grokys added this to the Beta 1 milestone Jan 26, 2018
@jkoritzinsky jkoritzinsky deleted the measure-with-forced-size branch September 18, 2018 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants