-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fixed issue where group Header/Footer template was applied to all items when IsGrouped was true for an ObservableCollection #28886
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
Tamilarasan-Paranthaman
wants to merge
6
commits into
dotnet:main
Choose a base branch
from
Tamilarasan-Paranthaman:fix-28827
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.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
767addb
Fixed group header template issue
Tamilarasan-Paranthaman 2f27a54
Added test sample
Tamilarasan-Paranthaman 99e004d
Added snapshots
Tamilarasan-Paranthaman ce0361c
test script changes
Tamilarasan-Paranthaman 0aeb498
Test sample changes
Tamilarasan-Paranthaman ce36a2d
Test sample changes
Tamilarasan-Paranthaman 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
+19.7 KB
...s.Android.Tests/snapshots/android/CVGroupHFTemplateWithObservableCollection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions
81
src/Controls/tests/TestCases.HostApp/Issues/Issue28827.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,81 @@ | ||
<?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.Issue28827" | ||
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues"> | ||
|
||
<Grid Padding="10" | ||
RowDefinitions="*, *"> | ||
<CollectionView | ||
Grid.Row="0" | ||
x:Name="collectionView" | ||
x:DataType="ns:Issue28827CollectionViewViewModel" | ||
ItemsSource="{Binding ItemsSource}" | ||
ItemTemplate="{Binding ItemTemplate}" | ||
IsGrouped="{Binding IsGrouped}" | ||
GroupHeaderTemplate="{Binding GroupHeaderTemplate}" | ||
GroupFooterTemplate="{Binding GroupFooterTemplate}" | ||
AutomationId="collectionView"> | ||
</CollectionView> | ||
|
||
<ScrollView Grid.Row="1"> | ||
<StackLayout Padding="10" | ||
Spacing="10"> | ||
<Label Text="GroupHeaderTemplate:" | ||
FontAttributes="Bold" | ||
FontSize="12"/> | ||
<StackLayout Orientation="Horizontal"> | ||
<RadioButton x:Name="GroupHeaderTemplateNone" | ||
IsChecked="True" | ||
CheckedChanged="OnGroupHeaderTemplateChanged" | ||
Content="None" | ||
FontSize="11" | ||
GroupName="GroupHeaderTemplateGroup" | ||
AutomationId="GroupHeaderTemplateNone"/> | ||
<RadioButton x:Name="GroupHeaderTemplateGrid" | ||
CheckedChanged="OnGroupHeaderTemplateChanged" | ||
Content="View" | ||
FontSize="11" | ||
GroupName="GroupHeaderTemplateGroup" | ||
AutomationId="GroupHeaderTemplateGrid"/> | ||
</StackLayout> | ||
|
||
<Label Text="GroupFooterTemplate:" | ||
FontAttributes="Bold" | ||
FontSize="12"/> | ||
<StackLayout Orientation="Horizontal"> | ||
<RadioButton x:Name="GroupFooterTemplateNone" | ||
IsChecked="True" | ||
CheckedChanged="OnGroupFooterTemplateChanged" | ||
Content="None" | ||
FontSize="11" | ||
GroupName="GroupFooterTemplateGroup" | ||
AutomationId="GroupFooterTemplateNone"/> | ||
<RadioButton x:Name="GroupFooterTemplateGrid" | ||
CheckedChanged="OnGroupFooterTemplateChanged" | ||
Content="View" | ||
FontSize="11" | ||
GroupName="GroupFooterTemplateGroup" | ||
AutomationId="GroupFooterTemplateGrid"/> | ||
</StackLayout> | ||
|
||
<Label Text="IsGrouped:" | ||
FontSize="12" | ||
FontAttributes="Bold"/> | ||
<StackLayout Orientation="Horizontal"> | ||
<RadioButton x:Name="IsGroupedFalse" | ||
Content="False" | ||
IsChecked="True" | ||
CheckedChanged="OnIsGroupedChanged" | ||
FontSize="11" | ||
AutomationId="IsGroupedFalse"/> | ||
<RadioButton x:Name="IsGroupedTrue" | ||
Content="True" | ||
CheckedChanged="OnIsGroupedChanged" | ||
FontSize="11" | ||
AutomationId="IsGroupedTrue"/> | ||
</StackLayout> | ||
</StackLayout> | ||
</ScrollView> | ||
</Grid> | ||
</ContentPage> |
214 changes: 214 additions & 0 deletions
214
src/Controls/tests/TestCases.HostApp/Issues/Issue28827.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,214 @@ | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.Github, 28827, "[Android] Group Header/Footer set for all Items when IsGrouped is True for ObservableCollection", PlatformAffected.Android)] | ||
public partial class Issue28827 : ContentPage | ||
{ | ||
Issue28827CollectionViewViewModel _viewModel; | ||
public Issue28827() | ||
{ | ||
InitializeComponent(); | ||
BindingContext = _viewModel = new Issue28827CollectionViewViewModel(); | ||
} | ||
|
||
void OnGroupHeaderTemplateChanged(object sender, CheckedChangedEventArgs e) | ||
{ | ||
if (GroupHeaderTemplateNone.IsChecked) | ||
{ | ||
_viewModel.GroupHeaderTemplate = null; | ||
} | ||
else if (GroupHeaderTemplateGrid.IsChecked) | ||
{ | ||
_viewModel.GroupHeaderTemplate = new DataTemplate(() => | ||
{ | ||
return new Grid | ||
{ | ||
BackgroundColor = Colors.LightGray, | ||
Padding = new Thickness(10), | ||
Children = | ||
{ | ||
new Label | ||
{ | ||
Text = "Group Header Template (Grid View)", | ||
FontSize = 18, | ||
FontAttributes = FontAttributes.Bold, | ||
HorizontalOptions = LayoutOptions.Center, | ||
VerticalOptions = LayoutOptions.Center, | ||
TextColor = Colors.Green | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
void OnGroupFooterTemplateChanged(object sender, CheckedChangedEventArgs e) | ||
{ | ||
if (GroupFooterTemplateNone.IsChecked) | ||
{ | ||
_viewModel.GroupFooterTemplate = null; | ||
} | ||
else if (GroupFooterTemplateGrid.IsChecked) | ||
{ | ||
_viewModel.GroupFooterTemplate = new DataTemplate(() => | ||
{ | ||
return new Grid | ||
{ | ||
BackgroundColor = Colors.LightGray, | ||
Padding = new Thickness(10), | ||
Children = | ||
{ | ||
new Label | ||
{ | ||
Text = "Group Footer Template (Grid View)", | ||
FontSize = 18, | ||
FontAttributes = FontAttributes.Bold, | ||
HorizontalOptions = LayoutOptions.Center, | ||
VerticalOptions = LayoutOptions.Center, | ||
TextColor = Colors.Red | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
void OnIsGroupedChanged(object sender, CheckedChangedEventArgs e) | ||
{ | ||
if (IsGroupedFalse.IsChecked) | ||
{ | ||
_viewModel.IsGrouped = false; | ||
} | ||
else if (IsGroupedTrue.IsChecked) | ||
{ | ||
_viewModel.IsGrouped = true; | ||
} | ||
} | ||
} | ||
|
||
public class Issue28827CollectionViewViewModel : INotifyPropertyChanged | ||
{ | ||
DataTemplate _groupHeaderTemplate; | ||
DataTemplate _groupFooterTemplate; | ||
DataTemplate _itemTemplate; | ||
bool _isGrouped = false; | ||
ObservableCollection<Issue28827ItemModel> _observableCollection; | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
public Issue28827CollectionViewViewModel() | ||
{ | ||
LoadItems(); | ||
ItemTemplate = new DataTemplate(() => | ||
{ | ||
var stackLayout = new StackLayout | ||
{ | ||
Padding = new Thickness(10), | ||
HorizontalOptions = LayoutOptions.Center, | ||
VerticalOptions = LayoutOptions.Center | ||
}; | ||
|
||
var label = new Label | ||
{ | ||
VerticalOptions = LayoutOptions.Center, | ||
HorizontalOptions = LayoutOptions.Center | ||
}; | ||
label.SetBinding(Label.TextProperty, "Caption"); | ||
stackLayout.Children.Add(label); | ||
return stackLayout; | ||
}); | ||
|
||
GroupHeaderTemplate = new DataTemplate(() => | ||
{ | ||
var stackLayout = new StackLayout | ||
{ | ||
BackgroundColor = Colors.LightGray | ||
}; | ||
var label = new Label | ||
{ | ||
FontAttributes = FontAttributes.Bold, | ||
FontSize = 18 | ||
}; | ||
label.SetBinding(Label.TextProperty, "Key"); | ||
stackLayout.Children.Add(label); | ||
return stackLayout; | ||
}); | ||
} | ||
|
||
void LoadItems() | ||
{ | ||
_observableCollection = new ObservableCollection<Issue28827ItemModel> | ||
{ | ||
new Issue28827ItemModel { Caption = "Item 1" }, | ||
new Issue28827ItemModel { Caption = "Item 2" }, | ||
new Issue28827ItemModel { Caption = "Item 3" } | ||
}; | ||
} | ||
|
||
public DataTemplate GroupHeaderTemplate | ||
{ | ||
get => _groupHeaderTemplate; | ||
set { _groupHeaderTemplate = value; OnPropertyChanged(); } | ||
} | ||
|
||
public DataTemplate GroupFooterTemplate | ||
{ | ||
get => _groupFooterTemplate; | ||
set { _groupFooterTemplate = value; OnPropertyChanged(); } | ||
} | ||
|
||
public DataTemplate ItemTemplate | ||
{ | ||
get => _itemTemplate; | ||
set { _itemTemplate = value; OnPropertyChanged(); } | ||
} | ||
|
||
public bool IsGrouped | ||
{ | ||
get => _isGrouped; | ||
set { _isGrouped = value; OnPropertyChanged(); } | ||
} | ||
|
||
public object ItemsSource | ||
{ | ||
get => _observableCollection; | ||
} | ||
|
||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null) | ||
{ | ||
if (propertyName == nameof(IsGrouped)) | ||
{ | ||
OnPropertyChanged(nameof(ItemsSource)); | ||
} | ||
|
||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
|
||
internal class Issue28827Grouping<TKey, TItem> : List<TItem> | ||
{ | ||
public TKey Key { get; } | ||
|
||
public Issue28827Grouping(TKey key, List<TItem> items) : base(items) | ||
{ | ||
Key = key; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Key?.ToString() ?? base.ToString(); | ||
} | ||
} | ||
|
||
internal class Issue28827ItemModel | ||
{ | ||
public string Caption { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return !string.IsNullOrEmpty(Caption) ? Caption : base.ToString(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28827.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,28 @@ | ||
#if TEST_FAILS_ON_WINDOWS // NullReferenceException occurs when switching isGrouped to true | ||
// refer to https://github.com/dotnet/maui/issues/28824 | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
||
public class Issue28827 : _IssuesUITest | ||
{ | ||
public override string Issue => "[Android] Group Header/Footer set for all Items when IsGrouped is True for ObservableCollection"; | ||
public Issue28827(TestDevice device) | ||
: base(device) | ||
{ } | ||
|
||
[Test] | ||
[Category(UITestCategories.CollectionView)] | ||
public void CVGroupHFTemplateWithObservableCollection() | ||
{ | ||
App.WaitForElement("collectionView"); | ||
App.Tap("IsGroupedTrue"); | ||
App.Tap("GroupHeaderTemplateGrid"); | ||
App.Tap("GroupFooterTemplateGrid"); | ||
|
||
VerifyScreenshot(); | ||
} | ||
} | ||
#endif |
Binary file added
BIN
+25.2 KB
...TestCases.iOS.Tests/snapshots/ios/CVGroupHFTemplateWithObservableCollection.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.
Uh oh!
There was an error while loading. Please reload this page.