Skip to content
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

.net 8 CollectionView Group Add method issue #21791

Open
Megral opened this issue Apr 12, 2024 · 4 comments
Open

.net 8 CollectionView Group Add method issue #21791

Megral opened this issue Apr 12, 2024 · 4 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@Megral
Copy link

Megral commented Apr 12, 2024

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

@Megral Megral added the t/bug Something isn't working label Apr 12, 2024
@jfversluis jfversluis added the s/needs-repro Attach a solution or code which reproduces the issue label Apr 15, 2024
@Megral Megral changed the title .net 8 ObservableCollection Add method issue .net 8 CollectionView Group Add method issue Apr 16, 2024
@kevinxufei
Copy link

kevinxufei commented Apr 18, 2024

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.
Screenshot 2024-04-18 100744

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Apr 18, 2024
@kevinxufei kevinxufei added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed s/needs-repro Attach a solution or code which reproduces the issue and removed s/needs-attention Issue has more information and needs another look s/needs-repro Attach a solution or code which reproduces the issue labels Apr 18, 2024
@samhouts samhouts added the potential-regression This issue described a possible regression on a currently supported version., verification pending label Apr 22, 2024
@Eilon Eilon added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Apr 30, 2024
@sharpwood
Copy link

I have also reproduced this issue.

@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jun 4, 2024
@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 10, 2024
@DavidV1603
Copy link

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 (xamarin/Xamarin.Forms#13268).
The following error is thrown:

Bildschirmfoto 2024-07-10 um 15 10 18 1

@larsduewel
Copy link

larsduewel commented Aug 10, 2024

Same error here, this one is quite annoying. Because in case you add items after switching pages, the collection view is not rendered anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants