-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Windows] Fixed CollectionView throws NRE when value of IsGrouped property is changed to false #27331
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 8 commits into
dotnet:inflight/current
from
NirmalKumarYuvaraj:fix-17864
Mar 24, 2026
Merged
[Windows] Fixed CollectionView throws NRE when value of IsGrouped property is changed to false #27331
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7652fb6
Remove stale PR note from Copilot instructions (#34566)
jfversluis b4dad75
Fix artifact upload collision in maui-pr-uitests pipeline (#34478)
lewing 5c24414
Fixed NRE when grouping changed
NirmalKumarYuvaraj 75cfeb0
updated code
NirmalKumarYuvaraj 1dbbf9f
Updated script file
NirmalKumarYuvaraj 70263fa
Updated code changes
NirmalKumarYuvaraj 1a22771
Updated code changes
NirmalKumarYuvaraj 50c4abc
Addressed AI summary concern
NirmalKumarYuvaraj 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
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
46 changes: 46 additions & 0 deletions
46
src/Controls/tests/TestCases.HostApp/Issues/Issue17864.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,46 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <controls:TestContentPage | ||
| xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue17864"> | ||
| <Grid> | ||
| <Grid.RowDefinitions> | ||
| <RowDefinition Height="Auto"/> | ||
| <RowDefinition Height="Auto"/> | ||
| <RowDefinition Height="*"/> | ||
| </Grid.RowDefinitions> | ||
|
|
||
| <Button Clicked="Button_Clicked" | ||
| AutomationId="Button" | ||
| Text="Disable Grouping"/> | ||
|
|
||
| <Button Grid.Row="1" | ||
| Clicked="EnableGroupingOnlyButton_Clicked" | ||
| AutomationId="EnableGroupingOnlyButton" | ||
| Text="Enable Grouping Without Regrouping"/> | ||
|
|
||
| <CollectionView Grid.Row="2" | ||
| AutomationId="CollectionView" | ||
| ItemsSource="{Binding Items}" | ||
| IsGrouped="{Binding IsGrouped}"> | ||
| <CollectionView.GroupHeaderTemplate> | ||
| <DataTemplate> | ||
| <Label Margin="2" | ||
| FontSize="Medium" | ||
| Text="{Binding ItemText}" | ||
| HorizontalOptions="Fill" | ||
| TextColor="LightBlue"/> | ||
| </DataTemplate> | ||
| </CollectionView.GroupHeaderTemplate> | ||
| <CollectionView.ItemTemplate> | ||
| <DataTemplate> | ||
| <Label Margin="15,2" | ||
| Text="{Binding ItemText}" | ||
| HorizontalOptions="Fill" | ||
| TextColor="Gray"/> | ||
| </DataTemplate> | ||
| </CollectionView.ItemTemplate> | ||
| </CollectionView> | ||
| </Grid> | ||
| </controls:TestContentPage> |
122 changes: 122 additions & 0 deletions
122
src/Controls/tests/TestCases.HostApp/Issues/Issue17864.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,122 @@ | ||
| using System.Collections.ObjectModel; | ||
| using System.ComponentModel; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues | ||
| { | ||
| [Issue(IssueTracker.Github, 17864, "[Windows] CollectionView throws NRE when value of IsGrouped property is changed to false", | ||
| PlatformAffected.UWP)] | ||
| public partial class Issue17864 : TestContentPage | ||
| { | ||
| readonly Issue17864_ItemListViewModel _ItemListViewModel; | ||
| protected override void Init() { } | ||
|
|
||
| public Issue17864() | ||
| { | ||
| InitializeComponent(); | ||
| _ItemListViewModel = new Issue17864_ItemListViewModel(); | ||
| BindingContext = _ItemListViewModel; | ||
| } | ||
|
|
||
| private void Button_Clicked(object sender, EventArgs e) | ||
| { | ||
| _ItemListViewModel.IsGrouped = !_ItemListViewModel.IsGrouped; | ||
| } | ||
|
|
||
| private void EnableGroupingOnlyButton_Clicked(object sender, EventArgs e) | ||
| { | ||
| _ItemListViewModel.EnableGroupingWithoutRegrouping(); | ||
| } | ||
| } | ||
|
|
||
| class Issue17864_GroupViewModel : ObservableCollection<Issue17864_ItemViewModel>, Issue17864_IItemViewModel | ||
| { | ||
|
|
||
| public Issue17864_GroupViewModel(int groupIndex) | ||
| { | ||
| ItemText = $"Group #{groupIndex}"; | ||
| } | ||
|
|
||
| public string ItemText { get; } | ||
| } | ||
|
|
||
| interface Issue17864_IItemViewModel | ||
| { | ||
| string ItemText { get; } | ||
| } | ||
|
|
||
| class Issue17864_ItemListViewModel : INotifyPropertyChanged | ||
| { | ||
| public event PropertyChangedEventHandler PropertyChanged; | ||
|
|
||
| ObservableCollection<Issue17864_IItemViewModel> items = new(); | ||
|
|
||
| private bool isGrouped = true; | ||
|
|
||
|
|
||
| public Issue17864_ItemListViewModel() | ||
| { | ||
| Populate(); | ||
| } | ||
|
|
||
| private void Populate() | ||
| { | ||
| items.Clear(); | ||
| if (isGrouped) | ||
| { | ||
| int groupIndex = 0; | ||
| items.Add(GetGroup(groupIndex++, 2)); | ||
| items.Add(GetGroup(groupIndex++, 1)); | ||
| items.Add(GetGroup(groupIndex++, 3)); | ||
| items.Add(GetGroup(groupIndex++, 2)); | ||
| } | ||
| else | ||
| { | ||
| int itemIndex = 0; | ||
| items.Add(new Issue17864_ItemViewModel(itemIndex++)); | ||
| items.Add(new Issue17864_ItemViewModel(itemIndex++)); | ||
| items.Add(new Issue17864_ItemViewModel(itemIndex++)); | ||
| } | ||
| } | ||
|
|
||
| private Issue17864_IItemViewModel GetGroup(int groupIndex, int itemCount) | ||
| { | ||
| var group = new Issue17864_GroupViewModel(groupIndex); | ||
| for (int i = 0; i < itemCount; i++) | ||
| { | ||
| group.Add(new Issue17864_ItemViewModel(i)); | ||
| } | ||
| return group; | ||
| } | ||
|
|
||
| public ObservableCollection<Issue17864_IItemViewModel> Items => items; | ||
|
|
||
| public void EnableGroupingWithoutRegrouping() | ||
| { | ||
| isGrouped = true; | ||
| PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsGrouped))); | ||
| } | ||
|
|
||
| public bool IsGrouped | ||
| { | ||
| get => isGrouped; | ||
| set | ||
| { | ||
| isGrouped = value; | ||
| Populate(); | ||
| PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsGrouped))); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class Issue17864_ItemViewModel : Issue17864_IItemViewModel | ||
| { | ||
|
|
||
| public Issue17864_ItemViewModel(int itemIndex) | ||
| { | ||
| ItemText = $"Item #{itemIndex}"; | ||
| } | ||
|
|
||
| public string ItemText { get; } | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue17864.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,31 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues | ||
| { | ||
| public class Issue17864 : _IssuesUITest | ||
| { | ||
| const string CollectionView = "CollectionView"; | ||
| public Issue17864(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "[Windows] CollectionView throws NRE when value of IsGrouped property is changed to false"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void CollectionViewShouldNotCrashWhenIsGroupedChangesInBothDirections() | ||
| { | ||
| App.WaitForElement(CollectionView); | ||
|
|
||
| // true -> false | ||
| App.Tap("Button"); | ||
| App.WaitForElement(CollectionView); | ||
|
|
||
| // false -> true while items remain flat | ||
| App.Tap("EnableGroupingOnlyButton"); | ||
| App.WaitForElement(CollectionView); | ||
| } | ||
| } | ||
| } | ||
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.
Ensure that the AutomationId for 'Button' is unique and not reused, or WaitForElement will fail to find the correct element.