Skip to content

Conversation

@BagavathiPerumal
Copy link
Contributor

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.

  • Windows
  • Mac
  • iOS
  • Android

Issues Fixed

Fixes #27646

Output

Before Issue Fix After Issue Fix
BeforeFix-AdaptiveTrigger.mp4
AfterFix-AdaptiveTrigger.mp4

… Changed callbacks to Window size properties.
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 33066

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 33066"

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 9, 2025
@karthikraja-arumugam karthikraja-arumugam added the community ✨ Community Contribution label Dec 9, 2025
@sheiksyedm sheiksyedm marked this pull request as ready for review December 9, 2025 12:18
Copilot AI review requested due to automatic review settings December 9, 2025 12:18
Copy link
Contributor

Copilot AI left a 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 OnSizePropertyChanged callback to WidthProperty and HeightProperty in 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.
Copy link

Copilot AI Dec 9, 2025

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.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,33 @@
#if WINDOWS // MacCatalyst don't support programmatic window resizing. So, ignored test on MacCatalyst.
Copy link

Copilot AI Dec 9, 2025

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.

Suggested change
#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.

Copilot uses AI. Check for mistakes.
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);
Copy link

Copilot AI Dec 9, 2025

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.

Suggested change
propertyChanged: OnSizePropertyChanged);
propertyChanged: OnSizePropertyChanged);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-window Window community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AdaptiveTrigger not firing when changing window width programmatically only

3 participants