Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Controls/src/Core/Window/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public partial class Window : NavigableElement, IWindow, IToolbarElement, IMenuB

/// <summary>Bindable property for <see cref="Width"/>.</summary>
public static readonly BindableProperty WidthProperty = BindableProperty.Create(
nameof(Width), typeof(double), typeof(Window), Primitives.Dimension.Unset);
nameof(Width), typeof(double), typeof(Window), Primitives.Dimension.Unset,
propertyChanged: OnSizePropertyChanged);

/// <summary>Bindable property for <see cref="Height"/>.</summary>
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.

/// <summary>Bindable property for <see cref="MaximumWidth"/>.</summary>
public static readonly BindableProperty MaximumWidthProperty = BindableProperty.Create(
Expand Down Expand Up @@ -228,6 +230,16 @@ double GetSizeCoordinate(BindableProperty property)

int _batchFrameUpdate = 0;

static void OnSizePropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var window = (Window)bindable;
// Only trigger SizeChanged if not being updated from platform (FrameChanged)
if (window._batchFrameUpdate == 0)
{
window.SizeChanged?.Invoke(window, EventArgs.Empty);
}
}

void IWindow.FrameChanged(Rect frame)
{
if (new Rect(X, Y, Width, Height) == frame)
Expand Down
99 changes: 99 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27646.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 27646, "AdaptiveTrigger not firing when changing window width programmatically only", PlatformAffected.UWP)]
public class Issue27646 : ContentPage
{
Label indicatorLabel;
Label statusLabel;

public Issue27646()
{
var stackLayout = new VerticalStackLayout
{
Padding = 20,
Spacing = 10
};

var instructionLabel = new Label
{
Text = "Click button to resize window. Label text should change at 600px window width.",
AutomationId = "InstructionLabel"
};
stackLayout.Add(instructionLabel);

statusLabel = new Label
{
Text = "Window width: Unknown",
AutomationId = "StatusLabel",
FontAttributes = FontAttributes.Bold
};
stackLayout.Add(statusLabel);

var resizeButton = new Button
{
Text = "Resize Window",
AutomationId = "ResizeButton"
};
resizeButton.Clicked += OnResizeClicked;
stackLayout.Add(resizeButton);

indicatorLabel = new Label
{
Text = "Initial",
WidthRequest = 200,
HeightRequest = 100,
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
AutomationId = "IndicatorLabel"
};
stackLayout.Add(indicatorLabel);

Content = stackLayout;

VisualStateManager.SetVisualStateGroups(indicatorLabel, new VisualStateGroupList
{
new VisualStateGroup
{
Name = "WindowWidthStates",
States =
{
new VisualState
{
Name = "Narrow",
StateTriggers =
{
new AdaptiveTrigger { MinWindowWidth = 0 }
},
Setters =
{
new Setter { Property = Label.TextProperty, Value = "Narrow Window" }
}
},
new VisualState
{
Name = "Wide",
StateTriggers =
{
new AdaptiveTrigger { MinWindowWidth = 600 }
},
Setters =
{
new Setter { Property = Label.TextProperty, Value = "Wide Window" }
}
}
}
}
});
}

void OnResizeClicked(object sender, EventArgs e)
{
if (Window is not null)
{
double newWidth = Window.Width >= 600 ? 550 : 650;
Window.Width = newWidth;

statusLabel.Text = $"Window width: {newWidth}px";
}
}
}
Original file line number Diff line number Diff line change
@@ -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.
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.
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue27646 : _IssuesUITest
{
public override string Issue => "AdaptiveTrigger not firing when changing window width programmatically only";

public Issue27646(TestDevice device) : base(device) { }

[Test]
[Category(UITestCategories.Window)]
public void AdaptiveTriggerShouldFireWhenWindowWidthChangedProgrammatically()
{
App.WaitForElement("ResizeButton");

App.Tap("ResizeButton");

var indicatorAfterFirstClick = App.FindElement("IndicatorLabel");
Assert.That(indicatorAfterFirstClick.GetText(), Is.EqualTo("Narrow Window"),
"Label should show 'Narrow Window' after resizing to 550px");

App.Tap("ResizeButton");

var indicatorAfterSecondClick = App.FindElement("IndicatorLabel");
Assert.That(indicatorAfterSecondClick.GetText(), Is.EqualTo("Wide Window"),
"Label should show 'Wide Window' after resizing to 650px");
}
}
#endif
Loading