Skip to content

.net 8 CollectionView Group Add method issue #21791

@Megral

Description

@Megral

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

MauiRepro-21791

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewCollectionView, CarouselView, IndicatorViewpartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/windowspotential-regressionThis issue described a possible regression on a currently supported version., verification pendings/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions