Skip to content

Call ApplyStyling unconditionally in MeasureCore - #21572

Merged
MrJul merged 6 commits into
AvaloniaUI:mainfrom
Fachep:fix_window_decorations
Aug 19, 2026
Merged

Call ApplyStyling unconditionally in MeasureCore#21572
MrJul merged 6 commits into
AvaloniaUI:mainfrom
Fachep:fix_window_decorations

Conversation

@Fachep

@Fachep Fachep commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

This PR moves ApplyStyling earlier in Layoutable.MeasureCore.

What is the current behavior?

Layoutable.MeasureCore currently applies styling after checking visibility, even though styling may affect the control's visibility.

Due to this, if a style in Window.Styles sets the IsVisible property of a control inside WindowDrawnDecorationsContent to false, the control is hidden but still reports its full size during the first measurement pass.

What is the updated/expected behavior with this PR?

Layoutable.MeasureCore now applies styling before performing visibility checks and measurement.

Controls hidden via styles now correctly produce an empty desired size in the same scenario. A unit test has been added to verify this behavior.

Checklist

Fixed issues

Fixes #21570

Copilot AI review requested due to automatic review settings June 12, 2026 14:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR fixes a layout/measurement issue where styling (e.g., setting IsVisible=false via styles) was not applied early enough to influence measurement, particularly for drawn window decorations.

Changes:

  • Added a unit test covering measurement of WindowDrawnDecorationsContent when styling hides a control.
  • Adjusted Layoutable.MeasureCore to apply styling before checking IsVisible, ensuring style-driven visibility changes are respected during measure.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/Avalonia.Controls.UnitTests/WindowTests.cs Adds regression test ensuring styled visibility affects measurement of drawn decoration overlay content.
src/Avalonia.Base/Layout/Layoutable.cs Applies styling earlier in measure so style changes (like visibility) take effect before measurement logic runs.

Comment thread src/Avalonia.Base/Layout/Layoutable.cs Outdated
Comment thread tests/Avalonia.Controls.UnitTests/WindowTests.cs Outdated
Comment thread tests/Avalonia.Controls.UnitTests/WindowTests.cs Outdated
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066351-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia

cla-avalonia commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator
  • All contributors have signed the CLA.

@Fachep

Fachep commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

@cla-avalonia agree

@Fachep Fachep changed the title Refactor MeasureCore and add unit test for WindowDrawnDecorations with Styles Refactor MeasureCore and add fix measurement for using WindowDrawnDecorations with Styles Jun 13, 2026
@Fachep
Fachep marked this pull request as draft June 13, 2026 13:59
@Fachep
Fachep force-pushed the fix_window_decorations branch from d6bd477 to be536ed Compare June 13, 2026 18:45
@Fachep
Fachep marked this pull request as ready for review June 13, 2026 18:46
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066393-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@Fachep Fachep changed the title Refactor MeasureCore and add fix measurement for using WindowDrawnDecorations with Styles Refactor MeasureCore and fix measurement for using WindowDrawnDecorations with Styles Jun 16, 2026
@Fachep
Fachep force-pushed the fix_window_decorations branch from be536ed to 232d415 Compare June 17, 2026 09:33
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066581-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@Fachep

Fachep commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

I have no idea about the failed integration test. It was the Windows test last time, after rebase to master it becomes the Mac test this time...

@Fachep
Fachep force-pushed the fix_window_decorations branch from 232d415 to 7e7334f Compare July 7, 2026 01:14
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0067229-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@Fachep

Fachep commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@MrJul Can you review this pls?

@MrJul MrJul added bug backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Aug 19, 2026
@MrJul MrJul changed the title Refactor MeasureCore and fix measurement for using WindowDrawnDecorations with Styles Call ApplyStyling unconditionally in MeasureCore Aug 19, 2026
@MrJul

MrJul commented Aug 19, 2026

Copy link
Copy Markdown
Member

You found a core framework bug here. It manifests more easily on WindowDrawnDecorations since that class doesn't have as many ApplyStyling() calls as standard controls, but the issue is real. See the test I added to your branch, which fails before this PR, with standard controls, no decorations involved: 4cb4192

I've modified the PR to just apply styles unconditionally in MeasureCore: 99% of the time they're already applied, so the call returns early and is basically free. It's also cheaper than checking IsVisible twice in a row, as you did (getting the value of a dependency property incurs a minimal cost, but it compounds in Measure/Arrange due to the sheer number of calls).

@MrJul
MrJul enabled auto-merge August 19, 2026 14:14
@MrJul
MrJul added this pull request to the merge queue Aug 19, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068509-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Merged via the queue into AvaloniaUI:main with commit 055e123 Aug 19, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Layout measurement issue for controls in WindowDrawnDecorationsContent when IsVisible=false is applied through Window.Styles

5 participants