-
Notifications
You must be signed in to change notification settings - Fork 2k
[Windows, MAC] - Fix Selected State Not Being Retained in CollectionView Items When PointerOver Is Applied #29815
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
Merged
kubaflo
merged 4 commits into
dotnet:inflight/current
from
prakashKannanSf3972:fix-29484
Mar 22, 2026
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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,82 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 29484, "CollectionView Selected state does not work on the selected item when combined with PointerOver", PlatformAffected.UWP | PlatformAffected.macOS)] | ||
| public class Issue29484 : TestContentPage | ||
| { | ||
| protected override void Init() | ||
| { | ||
| Style pointerOverSelectedStyle = CreatePointerOverSelectedItemStyle(); | ||
| DataTemplate pointerOverSelectedItemTemplate = CreateItemTemplate(pointerOverSelectedStyle); | ||
|
|
||
| Grid grid = new Grid | ||
| { | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| RowDefinitions = | ||
| { | ||
| new RowDefinition { Height = GridLength.Auto }, | ||
| new RowDefinition { Height = GridLength.Star }, | ||
| } | ||
| }; | ||
|
|
||
| grid.Add(new Label { Text = "PointerOverAndSelectedState" }, 0, 0); | ||
| grid.Add(InitializeCollectionView(pointerOverSelectedItemTemplate), 0, 1); | ||
| Content = grid; | ||
| } | ||
|
|
||
| CollectionView InitializeCollectionView(DataTemplate itemTemplate) | ||
| { | ||
| return new CollectionView | ||
| { | ||
| AutomationId = "CollectionView", | ||
| ItemTemplate = itemTemplate, | ||
| SelectionMode = SelectionMode.Single, | ||
| ItemsSource = new List<string> { "Item 1", "Item 2", "Item 3", "Item 4" } | ||
| }; | ||
| } | ||
|
|
||
| DataTemplate CreateItemTemplate(Style style) | ||
| { | ||
| return new DataTemplate(() => | ||
| { | ||
| Label label = new Label { Style = style }; | ||
| label.SetBinding(Label.TextProperty, "."); | ||
| return label; | ||
| }); | ||
| } | ||
|
|
||
| Style CreatePointerOverSelectedItemStyle() | ||
| { | ||
| return new Style(typeof(Label)) | ||
| { | ||
| Setters = | ||
| { | ||
| new Setter { Property = BackgroundColorProperty, Value = Colors.Transparent }, | ||
| new Setter | ||
| { | ||
| Property = VisualStateManager.VisualStateGroupsProperty, | ||
| Value = CreateVisualState() | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| VisualStateGroupList CreateVisualState() | ||
| { | ||
| VisualStateGroupList groupList = new VisualStateGroupList(); | ||
| VisualStateGroup commonStates = new VisualStateGroup { Name = "CommonStates" }; | ||
|
|
||
| VisualState normalState = new VisualState { Name = "Normal" }; | ||
| VisualState pointerOverState = new VisualState { Name = "PointerOver" }; | ||
| VisualState selectedState = new VisualState { Name = "Selected" }; | ||
|
|
||
| pointerOverState.Setters.Add(new Setter { Property = BackgroundColorProperty, Value = Colors.DarkTurquoise }); | ||
| selectedState.Setters.Add(new Setter { Property = BackgroundColorProperty, Value = Colors.DarkBlue }); | ||
|
|
||
| commonStates.States.Add(pointerOverState); | ||
| commonStates.States.Add(selectedState); | ||
| commonStates.States.Add(normalState); | ||
|
|
||
| groupList.Add(commonStates); | ||
| return groupList; | ||
| } | ||
| } |
Binary file added
BIN
+11.7 KB
...ts/TestCases.Mac.Tests/snapshots/mac/PointerOverWithSelectedStateShouldWork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions
27
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29484.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,27 @@ | ||
| #if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_IOS | ||
| // This test is disabled on mobile platforms because they do not support pointer hover states. | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue29484 : _IssuesUITest | ||
| { | ||
| public Issue29484(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "CollectionView Selected state does not work on the selected item when combined with PointerOver"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void PointerOverWithSelectedStateShouldWork() | ||
| { | ||
| App.WaitForElement("CollectionView"); | ||
| App.Tap("Item 2"); | ||
| App.Tap("PointerOverAndSelectedState"); | ||
| VerifyScreenshot(); | ||
| } | ||
| } | ||
| #endif |
Binary file added
BIN
+7.9 KB
...tCases.WinUI.Tests/snapshots/windows/PointerOverWithSelectedStateShouldWork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Can simplify it reduced duplicate calls to
VisualStateManager.GoToState: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.
@jsuarezruiz, I have updated the changes as suggested.