问题描述
使用VS社区2015.
我创建了一个线程安全列表(TList< T>),它实现了线程中的所有标准列表功能 - 安全的方式。我现在有一个具有TList< ImageEntry>的用户控件。作为财产。 ImageEntry是从Component派生的对象,具有3个属性。但是,CollectionEditor不允许在设计器中维护此列表。
TList:
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;
}
.... // All the list functionality here
}
内容:
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; }
}
当我在IDE中调出CollectionEditor时,它不会在右边显示ImageEntry属性,并在左侧禁用添加和删除按钮。但是,如果我修改Images属性使其返回内部List< ImageEntry>,它一切正常(但当然,我的Images属性不是线程安全的)。
我尝试过组合一个自定义的Collection编辑器,但这也不起作用。
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?
推荐答案
这篇关于自定义列表类型的集合编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!