-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
🚧 work in progressWork that is current in progressWork that is current in progressarea-DesignerSupport
Milestone
Description
.NET version
9.0.100-rc.1.24452.12
Did it work in .NET Framework?
Not tested/verified
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
Description
The Remove(Image value) and IndexOf(Image value) methods in the ImageListDesigner.OriginalImageCollection class currently operate incorrectly when interacting with ImageListImage. These methods are intended to work with ImageListImage objects but only handle the base Image class, causing unintended behavior when removing or searching for items in the collection.
Expected Behavior
Remove()should remove anImageListImagefrom the collection if it exists.IndexOf()should return the correct index of anImageListImagein the collection.
Actual Behavior
Remove()does not correctly remove theImageListImageobject from the collection, because it only checks for the baseImagetype.IndexOf()returns-1or an incorrect index, because it also checks for the baseImagetype, notImageListImage.
Affected Code
public int IndexOf(Image? value) => value is Image image ? _items.IndexOf(image) : -1;
public void Remove(Image value)
{
AssertInvariant();
_items.Remove(value);
RecreateHandle();
}Both methods are currently checking for Image rather than ImageListImage, which leads to issues when working with the collection.
Suggested Fix
Modify the Remove() and IndexOf() methods to handle ImageListImage objects explicitly.
- For the IndexOf() method:
public int IndexOf(ImageListImage? value) => value is ImageListImage imageListImage ? _items.IndexOf(imageListImage) : -1;
int IList.IndexOf(object? value) => value is ImageListImage image ? IndexOf(image) : -1;- For the Remove() method:
public void Remove(ImageListImage value)
{
AssertInvariant();
_items.Remove(value);
RecreateHandle();
}
void IList.Remove(object? value)
{
if (value is ImageListImage image)
{
Remove(image);
}
}Steps to reproduce
- Create an instance of
ImageListDesigner.OriginalImageCollection. - Add
ImageListImageobjects to the collection using theAddmethod. - Attempt to remove or find an item using the
Remove()orIndexOf()method, passing anImageListImage.
Tanya-Solyanik and LeafShi1
Metadata
Metadata
Assignees
Labels
🚧 work in progressWork that is current in progressWork that is current in progressarea-DesignerSupport
