-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Windows]Fix for AdaptiveTrigger Not Firing When Changing Window Width Programmatically #33066
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
base: main
Are you sure you want to change the base?
Conversation
… Changed callbacks to Window size properties.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 33066Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 33066" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a Windows-specific issue where AdaptiveTrigger visual states fail to update when window dimensions are changed programmatically. The fix adds property change callbacks to the Width and Height properties that fire the SizeChanged event immediately when properties are set from user code, using the existing _batchFrameUpdate flag to prevent duplicate events during platform-initiated updates.
Key changes:
- Added
OnSizePropertyChangedcallback toWidthPropertyandHeightPropertyin Window.cs - Created comprehensive UI test validating AdaptiveTrigger behavior with programmatic window resizing
- Test includes both HostApp page and NUnit test implementation following MAUI UI testing patterns
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Controls/src/Core/Window/Window.cs | Added propertyChanged callbacks to Width/Height properties that fire SizeChanged event when updated programmatically (not from platform) |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27646.cs | NUnit UI test verifying AdaptiveTrigger fires when window width changes programmatically, currently Windows-only |
| src/Controls/tests/TestCases.HostApp/Issues/Issue27646.cs | HostApp test page with AdaptiveTrigger visual states and programmatic window resizing button |
| @@ -0,0 +1,33 @@ | |||
| #if WINDOWS // MacCatalyst don't support programmatic window resizing. So, ignored test on MacCatalyst. | |||
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test uses #if WINDOWS but the comment says "MacCatalyst don't support programmatic window resizing." However, looking at Issue26083.cs which also tests window resizing behavior, it uses #if WINDOWS || MACCATALYST.
The fix in Window.cs is platform-agnostic and should work on MacCatalyst as well. Consider whether MacCatalyst actually supports programmatic window resizing and if it does, update the conditional to #if WINDOWS || MACCATALYST to match the pattern used in Issue26083.cs and provide broader test coverage.
| @@ -0,0 +1,33 @@ | |||
| #if WINDOWS // MacCatalyst don't support programmatic window resizing. So, ignored test on MacCatalyst. | |||
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammatical error in the comment. Change "MacCatalyst don't support" to "MacCatalyst doesn't support" for correct subject-verb agreement.
| #if WINDOWS // MacCatalyst don't support programmatic window resizing. So, ignored test on MacCatalyst. | |
| #if WINDOWS // MacCatalyst doesn't support programmatic window resizing. So, ignored test on MacCatalyst. |
| public static readonly BindableProperty HeightProperty = BindableProperty.Create( | ||
| nameof(Height), typeof(double), typeof(Window), Primitives.Dimension.Unset); | ||
| nameof(Height), typeof(double), typeof(Window), Primitives.Dimension.Unset, | ||
| propertyChanged: OnSizePropertyChanged); |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected after the closing parenthesis. Please remove the extra spaces at the end of line 53 to maintain consistent code formatting.
| propertyChanged: OnSizePropertyChanged); | |
| propertyChanged: OnSizePropertyChanged); |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root cause
The issue occurs because of the order of operations when window dimensions are changed programmatically versus manually. The FrameChanged() method determines whether to fire the SizeChanged event by comparing current property values against incoming frame values. During manual resize operations, the platform invokes FrameChanged() first, which then updates the Width and Height properties, successfully detecting the change and firing the event.
However, during programmatic resize, the Width and Height properties update immediately upon assignment. When the platform subsequently invokes FrameChanged(), the property values already match the incoming frame values, causing the comparison to fail and preventing the SizeChanged event from firing. This breaks AdaptiveTrigger functionality, which depends on the SizeChanged event to update visual states.
Description of Issue Fix
The fix involves adding propertyChanged callbacks to WidthProperty and HeightProperty that fire the SizeChanged event immediately when properties change from user code. The existing _batchFrameUpdate flag distinguishes between user-initiated changes (flag equals zero) and platform-initiated changes (flag greater than zero), preventing duplicate event firing. When user code sets Width or Height programmatically, the callback fires SizeChanged directly.
When the platform updates properties through FrameChanged(), the callback is suppressed and the existing event logic handles notification. This ensures AdaptiveTrigger receives notifications for both programmatic and manual resizes without duplicates, following the established pattern used by ColumnDefinition and RowDefinition in MAUI's Grid layout system.
Tested the behavior in the following platforms.
Issues Fixed
Fixes #27646
Output
BeforeFix-AdaptiveTrigger.mp4
AfterFix-AdaptiveTrigger.mp4