-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix for VisualStateManager Setter.TargetName failing when ControlTemplate is applied #33208
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
Open
BagavathiPerumal
wants to merge
1
commit into
dotnet:main
Choose a base branch
from
BagavathiPerumal:fix-26977
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+117
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Controls/tests/TestCases.HostApp/Issues/Issue26977.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue26977"> | ||
| <ContentPage.ControlTemplate> | ||
| <ControlTemplate> | ||
| <ContentPresenter/> | ||
| </ControlTemplate> | ||
| </ContentPage.ControlTemplate> | ||
|
|
||
| <VerticalStackLayout x:Name="RootStackLayout" | ||
| Padding="30,0" | ||
| Spacing="25" | ||
| VerticalOptions="Center"> | ||
| <HorizontalStackLayout Spacing="10"> | ||
| <Label Text="Active State" | ||
| VerticalOptions="Center"/> | ||
| <Switch x:Name="StateSwitch" | ||
| AutomationId="StateSwitch" | ||
| Toggled="OnStateSwitchToggled"/> | ||
| </HorizontalStackLayout> | ||
|
|
||
| <Label x:Name="TargetLabel" | ||
| AutomationId="TargetLabel"/> | ||
|
|
||
| <VisualStateManager.VisualStateGroups> | ||
| <VisualStateGroup Name="Group1"> | ||
| <VisualState Name="State1"> | ||
| <VisualState.Setters> | ||
| <Setter TargetName="TargetLabel" | ||
| Property="Label.Text" | ||
| Value="Value from Setter in State1"/> | ||
| <Setter TargetName="TargetLabel" | ||
| Property="Label.BackgroundColor" | ||
| Value="Orange"/> | ||
| </VisualState.Setters> | ||
| </VisualState> | ||
| <VisualState Name="State2"> | ||
| <VisualState.Setters> | ||
| <Setter TargetName="TargetLabel" | ||
| Property="Label.Text" | ||
| Value="Value from Setter in State2"/> | ||
| <Setter TargetName="TargetLabel" | ||
| Property="Label.BackgroundColor" | ||
| Value="Aqua"/> | ||
| </VisualState.Setters> | ||
| </VisualState> | ||
| </VisualStateGroup> | ||
| </VisualStateManager.VisualStateGroups> | ||
| </VerticalStackLayout> | ||
| </ContentPage> |
20 changes: 20 additions & 0 deletions
20
src/Controls/tests/TestCases.HostApp/Issues/Issue26977.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 26977, "Setter.TargetName + ControlTemplate crash", PlatformAffected.Android)] | ||
| public partial class Issue26977 : ContentPage | ||
| { | ||
| public Issue26977() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
|
|
||
| void OnStateSwitchToggled(object sender, ToggledEventArgs e) | ||
| { | ||
| if (sender is not Switch stateSwitch) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| VisualStateManager.GoToState(RootStackLayout, stateSwitch.IsToggled ? "State1" : "State2"); | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26977.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue26977 : _IssuesUITest | ||
| { | ||
| public Issue26977(TestDevice device) : base(device) { } | ||
|
|
||
| public override string Issue => "Setter.TargetName + ControlTemplate crash"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Page)] | ||
| public void SetterTargetNameWithControlTemplateShouldNotCrash() | ||
| { | ||
| App.WaitForElement("StateSwitch"); | ||
| App.Tap("StateSwitch"); | ||
|
|
||
| var normalText = App.FindElement("TargetLabel").GetText(); | ||
| Assert.That(normalText, Is.EqualTo("Value from Setter in State1"), | ||
| "Label text should change to 'Value from Setter in State1' after the switch is toggled"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 PlatformAffected should be set to PlatformAffected.All instead of PlatformAffected.Android. According to the PR description, this fix was tested on Android, Windows, iOS, and Mac. The issue is a VisualStateManager namescope resolution problem that affects all platforms where ControlTemplates create namescope boundaries, not just Android.