Repository navigation
[iOS]Fix CollectionView items not rendered properly when SelectedItem assigned in ApplyQueryAttributes #38614
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 7 commits into
dotnet:inflight/current
from
devanathan-vaithiyanathan:fix-38443
Sep 23, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0e4db26
fix added
devanathan-vaithiyanathan 092eec1
test added
devanathan-vaithiyanathan 6165d29
review concern addressed
devanathan-vaithiyanathan 1fb9586
Update SelectableItemsViewController2.cs
devanathan-vaithiyanathan 337aae9
images added
devanathan-vaithiyanathan 5f49a58
iOS snap added
devanathan-vaithiyanathan df2ffda
Update SelectableItemsViewController2.cs
devanathan-vaithiyanathan 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
Binary file added
BIN
+43 KB
...ts/snapshots/android/SelectedItemSetDuringShellNavigationUpdatesVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
163 changes: 163 additions & 0 deletions
163
src/Controls/tests/TestCases.HostApp/Issues/Issue38443.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,163 @@ | ||
| #nullable enable | ||
| using System.Collections.ObjectModel; | ||
| using System.ComponentModel; | ||
| using System.Runtime.CompilerServices; | ||
| using Microsoft.Maui.Controls.Shapes; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 38443, "CollectionView SelectedItem set during Shell navigation does not update the visual state", PlatformAffected.iOS | PlatformAffected.macOS)] | ||
| public class Issue38443 : TestShell | ||
| { | ||
| const string DetailRoute = "Issue38443Detail"; | ||
|
|
||
| protected override void Init() | ||
| { | ||
| Routing.RegisterRoute(DetailRoute, typeof(Issue38443DetailPage)); | ||
|
|
||
| var navigateButton = new Button | ||
| { | ||
| AutomationId = "NavigateButton", | ||
| Text = "Navigate to CollectionView" | ||
| }; | ||
| navigateButton.Clicked += async (sender, args) => await GoToAsync(DetailRoute); | ||
|
|
||
| Items.Add(new ShellContent | ||
| { | ||
| Title = "Issue 38443", | ||
| Content = new ContentPage | ||
| { | ||
| Content = new Grid | ||
| { | ||
| Children = { navigateButton } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public class Issue38443DetailPage : ContentPage, IQueryAttributable, INotifyPropertyChanged | ||
| { | ||
| string? _selectedBoxColor; | ||
|
|
||
| public Issue38443DetailPage() | ||
| { | ||
| Title = "Box Colors"; | ||
| BindingContext = this; | ||
|
|
||
| var collectionView = new CollectionView | ||
| { | ||
| AutomationId = "ColorsCollectionView", | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| ItemsSource = BoxColors, | ||
| SelectionMode = SelectionMode.Single, | ||
| VerticalOptions = LayoutOptions.Center, | ||
| ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical) | ||
| { | ||
| ItemSpacing = 5 | ||
| }, | ||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| var boxView = new BoxView | ||
| { | ||
| HeightRequest = 40, | ||
| WidthRequest = 40 | ||
| }; | ||
| boxView.SetBinding(BoxView.ColorProperty, "."); | ||
|
|
||
| var border = new Border | ||
| { | ||
| Padding = 4, | ||
| Stroke = Colors.Transparent, | ||
| StrokeShape = new RoundRectangle { CornerRadius = 4 }, | ||
| StrokeThickness = 3, | ||
| Content = boxView | ||
| }; | ||
|
|
||
| VisualStateManager.SetVisualStateGroups(border, | ||
| [ | ||
| new VisualStateGroup | ||
| { | ||
| Name = "CommonStates", | ||
| States = | ||
| { | ||
| new VisualState { Name = "Normal" }, | ||
| new VisualState | ||
| { | ||
| Name = "Selected", | ||
| Setters = | ||
| { | ||
| new Setter { Property = Border.StrokeProperty, Value = Colors.Black } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ]); | ||
|
|
||
| return border; | ||
| }) | ||
| }; | ||
| collectionView.SetBinding(SelectableItemsView.SelectedItemProperty, nameof(SelectedBoxColor)); | ||
|
|
||
| var instructionsLabel = new Label | ||
| { | ||
| HorizontalTextAlignment = TextAlignment.Center, | ||
| AutomationId = "InstructionsLabel", | ||
| Text = "Expected: the cyan item is selected when this page opens." | ||
| }; | ||
|
|
||
| var selectedColorLabel = new Label | ||
| { | ||
| AutomationId = "SelectedColorLabel", | ||
| HorizontalTextAlignment = TextAlignment.Center | ||
| }; | ||
| selectedColorLabel.SetBinding(Label.TextProperty, new Binding(nameof(SelectedBoxColor), stringFormat: "SelectedItem: {0}")); | ||
|
|
||
| var content = new Grid | ||
| { | ||
| Padding = 24, | ||
| RowSpacing = 16, | ||
| RowDefinitions = | ||
| { | ||
| new RowDefinition(GridLength.Auto), | ||
| new RowDefinition(GridLength.Star), | ||
| new RowDefinition(GridLength.Auto) | ||
| } | ||
| }; | ||
| content.Add(instructionsLabel); | ||
| content.Add(collectionView, row: 1); | ||
| content.Add(selectedColorLabel, row: 2); | ||
|
|
||
| Content = content; | ||
| } | ||
|
|
||
| public ObservableCollection<string> BoxColors { get; } = | ||
| [ | ||
| "#113FFC", "#00A1CD", "#7c0e64", "#d2a023", "#ca1765", "#14e147" | ||
| ]; | ||
|
|
||
| public string? SelectedBoxColor | ||
| { | ||
| get => _selectedBoxColor; | ||
| set | ||
| { | ||
| if (_selectedBoxColor == value) | ||
| return; | ||
|
|
||
| _selectedBoxColor = value; | ||
| OnPropertyChanged(); | ||
| } | ||
| } | ||
|
|
||
| public void ApplyQueryAttributes(IDictionary<string, object> query) | ||
| { | ||
| SelectedBoxColor = BoxColors[1]; | ||
| } | ||
|
|
||
| public new event PropertyChangedEventHandler? PropertyChanged; | ||
|
|
||
| protected new void OnPropertyChanged([CallerMemberName] string? propertyName = null) | ||
| { | ||
| PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
| } | ||
| } |
Binary file added
BIN
+19.7 KB
....Tests/snapshots/mac/SelectedItemSetDuringShellNavigationUpdatesVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions
25
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue38443.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,25 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| internal class Issue38443 : _IssuesUITest | ||
| { | ||
| public Issue38443(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "CollectionView SelectedItem set during Shell navigation does not update the visual state"; | ||
|
|
||
| [Test] | ||
| [ShardedTestCategory(UITestCategories.CollectionView, shard: 1)] | ||
| public void SelectedItemSetDuringShellNavigationUpdatesVisualState() | ||
| { | ||
| App.WaitForElement("NavigateButton"); | ||
| App.Tap("NavigateButton"); | ||
|
|
||
| App.WaitForElement("InstructionsLabel"); | ||
| VerifyScreenshot(); | ||
|
devanathan-vaithiyanathan marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
Binary file added
BIN
+11.8 KB
...ts/snapshots/windows/SelectedItemSetDuringShellNavigationUpdatesVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+47.5 KB
...sts/snapshots/ios-26/SelectedItemSetDuringShellNavigationUpdatesVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.8 KB
....Tests/snapshots/ios/SelectedItemSetDuringShellNavigationUpdatesVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Uh oh!
There was an error while loading. Please reload this page.