I have a grouped list in C# MAUI MVVC, destination is Andoid
public class GroupData : ObservableCollection<DetailData>
{
public string Name { get; private set; }
public GroupData(string name, ObservableCollection<DetailData> d) : base(d)
{ Name = name; }
}
public class DetailData
{
public int Nr { get; set; }
public string Detail { get; set; }
}
Test data are added like this
public ObservableCollection<GroupData> GetData()
{
ObservableCollection<GroupData> data = new ObservableCollection<GroupData>();
data.Add(new GroupData("Group1", new ObservableCollection<DetailData>
{
new DetailData { Nr = 1, Detail = "Test 1" },
new DetailData { Nr = 2, Detail = "Test 2" }
}));
data.Add(new GroupData("Group2", new ObservableCollection<DetailData>
{
new DetailData { Nr = 3, Detail = "Test 3" },
new DetailData { Nr = 4, Detail = "Test 4" }
}));
return data;
}
Main Page View Model has the bindable collection
public ObservableCollection<GroupData> GroupData { get; } = new ObservableCollection<GroupData>();
and an event on a button when showing the list.
Clicking on it should remove the selected item.
[RelayCommand]
private async Task ButtonOk(DetailData data)
{
foreach (var item in GroupData)
{
foreach (var child in item)
{
if (child.Nr == data.Nr)
{
item.Remove(child);
break;
}
}
}
}
Description
I have a grouped list in C# MAUI MVVC, destination is Andoid
Test data are added like this
Main Page View Model has the bindable collection
public ObservableCollection<GroupData> GroupData { get; } = new ObservableCollection<GroupData>();
and an event on a button when showing the list. Clicking on it should remove the selected item.
Data are shown with this
Now, when adding ONLY ONE grouped item to the observable collection "Group 1" with the two childs the removing works perfect.
But when adding a SECOND "Group 2" it unfortunately fails with error
Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView() on the child's parent first.'
Steps to Reproduce
see code and description
Link to public reproduction project repository
No response
Version with bug
8.0.93 SR9.3
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
No response
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
remove
Relevant log output