-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||||||
|
||||||
| #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. |
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.