Using VS Community 2015.
I have create a thread-safe list (TList<T>) that implements all of the standard list functionality in a thread-safe manner. I now have a user control that has a TList<ImageEntry> as a property. ImageEntry is an object derived from Component, with 3 properties. However, the CollectionEditor does not allow maintenance of this list in the designer.
The TList:
public class TList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IDisposable {
private ReaderWriterLockSlim _lck = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
private List<T> _list = new List<T>();
private bool _lockableEnumerator = false;
public TList() { }
public TList(bool lockableEnumerator) : base() {
_lockableEnumerator = lockableEnumerator;
}
public TList(IEnumerable<T> elements, bool lockableEnumerator = false) {
_list.AddRange(elements);
_lockableEnumerator = lockableEnumerator;
}
....
}
The contents:
[DesignTimeVisible(false)]
public class ImageEntry : Component {
protected Bitmap _image = null;
protected string _path = null;
ImageDrawMode _sizemode = ImageDrawMode.Zoom;
public ImageEntry() { }
[DefaultValue(typeof(Bitmap), null)]
public virtual Bitmap Image {
get {
if (_image == null) {
if (!string.IsNullOrEmpty(_path))
_image = new Bitmap(_path);
}
return _image;
}
set {
_image = value;
if (value != null)
_path = null;
}
}
[DefaultValue(typeof(string), "")]
public virtual string Path {
get { return _path ?? string.Empty; }
set {
if (string.IsNullOrEmpty(value))
_path = null;
else {
_image = null;
_path = value;
}
}
}
[DefaultValue(ImageDrawMode.Zoom)]
public virtual ImageDrawMode SizeMode {
get {
return _sizemode;
}
set {
_sizemode = value;
}
}
public override string ToString() {
return string.IsNullOrEmpty(_path) ? ((_image == null) ? null : _image.ToString()) : _path;
}
}
The property:
TList<ImageEntry> _images = new TList<ImageEntry>();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Description("The collection of images to cycle through")]
[Category("Effects")]
[Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
public TList<ImageEntry> Images {
get { return _images; }
}
When I bring up the CollectionEditor in the IDE, it does not show the ImageEntry properties on the right, and the Add and Remove buttons are disabled on the left. However, if I modify the Images property such that it returns the internal List<ImageEntry>, it all works fine (but then, of course, my Images property is not thread-safe).
I have tried putting together a custom Collection editor, but that didn't work either.
public class ImageEntryCollectionEditor : CollectionEditor {
public ImageEntryCollectionEditor(Type type) : base(type) { }
protected override Type[] CreateNewItemTypes() {
return new Type[] { typeof(ImageEntry) };
}
protected override Type CreateCollectionItemType() {
return typeof(ImageEntry);
}
}
What am I missing here?