maui
maui copied to clipboard
.net 8 CollectionView Group Add method issue
Description
##Issue If enabled isGrouped, program stop at A.Add(group); and throw a Unhandled Win32 exceptions message
##Code ViewMode
List<List<ModelGroup>> ggParameters = new List<List<ModelGroup>>();
public RelayCommand<int> AddTestCommand { get; }
public MainViewModel()
{
AddTestCommand = new RelayCommand<int>(AddTest);
ggParameters.Add(new List<ModelGroup>
{
new ModelGroup("group1", new List<Model>
{
new Model(),
new Model(),
new Model(),
}),
new ModelGroup("group2", new List<Model>
{
new Model(),
new Model(),
new Model(),
}),
});
B.Add(new GroupButton("Class1", 0, new RelayCommand<int>(ChangeShowedClass)));
ggParameters.Add(new List<ModelGroup>
{
new ModelGroup("group3", new List<Model>
{
new Model(),
new Model(),
new Model(),
}),
new ModelGroup("group4", new List<Model>
{
new Model(),
new Model(),
new Model(),
}),
});
B.Add(new GroupButton("Class2", 1, new RelayCommand<int>(ChangeShowedClass)));
foreach (ModelGroup group in ggParameters[0])
{
A.Add(group);
}
C.Add("111");
}
private ObservableCollection<ModelGroup> _A = new ObservableCollection<ModelGroup>();
public ObservableCollection<ModelGroup> A
{
get => _A;
set
{
_A = value;
OnPropertyChanged();
}
}
private ObservableCollection<GroupButton> _B = new ObservableCollection<GroupButton>();
public ObservableCollection<GroupButton> B
{
get => _B;
set
{
_B = value;
OnPropertyChanged();
}
}
private ObservableCollection<string> _C = new ObservableCollection<string>();
public ObservableCollection<string> C
{
get => _C;
set
{
_C = value;
OnPropertyChanged();
}
}
private int _TestInt = 0;
public int TestInt
{
get => _TestInt;
set
{
_TestInt = value;
OnPropertyChanged();
}
}
private void ChangeShowedClass(int index)
{
A.Clear();
foreach (ModelGroup group in ggParameters[index])
{
A.Add(group);
}
}
private void AddTest(int index)
{
if (index == 0)
{
C.Add("1111");
}
else
{
C.Add("2222");
}
}
##Code Model
public class Model
{
public string Name { get; set; }
public Model()
{
Name = "-";
}
}
public class ModelGroup : List<Model>
{
public string GroupName { get; set; }
public ModelGroup(string groupName, List<Model> models) : base(models)
{
GroupName = groupName;
}
}
public class GroupButton : ObservableObject
{
public string ButtonName { get; set; }
public int ButtonNum { get; set; }
public RelayCommand<int> ButtonCommand { get; set; }
public GroupButton(string button_name, int button_num, RelayCommand<int> button_command)
{
ButtonName = button_name;
ButtonNum = button_num;
ButtonCommand = button_command;
}
}
##Code View
<StackLayout Grid.Column="0" BindableLayout.ItemsSource="{Binding B}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Button Text="{Binding ButtonName}" Command="{Binding ButtonCommand}" CommandParameter="{Binding ButtonNum}"/>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
<CollectionView Grid.Row="1" ItemsSource="{Binding A}" IsGrouped="True" ItemSizingStrategy="MeasureFirstItem">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical" ItemSpacing="1"/>
</CollectionView.ItemsLayout>
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<Label Text="{Binding GroupName}" FontAttributes="Bold" HeightRequest="30" VerticalTextAlignment="Center"/>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border Padding="4" HeightRequest="45">
<Grid RowSpacing="3" RowDefinitions="auto, auto">
<Grid ColumnDefinitions="*, 200, *">
<Label Text="{Binding Name}" VerticalTextAlignment="Center"/>
</Grid>
</Grid>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.Footer>
<Label Text="- The End -" HorizontalTextAlignment="Center"/>
</CollectionView.Footer>
</CollectionView>
<CollectionView Grid.Row="1" ItemsSource="{Binding C}" ItemSizingStrategy="MeasureFirstItem">
</CollectionView>
<Entry Text="{Binding TestInt}"/>
<Button Text="AddTest" Command="{Binding AddTestCommand}" CommandParameter="{Binding TestInt}"/>
Steps to Reproduce
Start program and click Class1 or Class2 button
Link to public reproduction project repository
Version with bug
8.0.3 GA
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
7.0.101
Affected platforms
Windows
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response
Verified this issue with Visual Studio 17.10.0 Preview 3 ( 8.0.20/8.0.0-rc.2.9530), Can repro issue with sample project.
Hi @Megral. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
I have also reproduced this issue.
I can also reproduce this crash in my app. It occurs on iOS devices when IsGrouped = true and the add-method gets called. On Android it does not appear.
It seems to be the same error that was also reported in Xamarin.Forms (https://github.com/xamarin/Xamarin.Forms/issues/13268). The following error is thrown:
Same error here, this one is quite annoying. Because in case you add items after switching pages, the collection view is not rendered anymore.