【发布时间】:2011-04-14 15:52:44
【问题描述】:
我有一个具有Items 属性的自定义控件。我已经应用了 EditorAttribute 和 UITypeEditor 类型的 CollectionEditor。
收藏类型:
[Serializable]
[Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
public class ListItemsCollection : CollectionBase
{
// methods
}
控件中的属性声明:
private new ListItemsCollection _Items;
[Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
public new ListItemsCollection Items
{
get
{
return _Items;
}
set
{
_Items = value;
// do other UI changes
}
}
问题:
当我将此控件放到设计器表面时,我可以使用 PropertyGrid 将项目添加到 Items 属性。但是,当我单击CollectionEditor 的Ok 按钮时,Items 属性的设置器没有被调用。
当从UITypeEditor 类的EditValue 方法返回值时,应该调用属性的设置器块。
这让我发疯了。我什至尝试将Event添加到ListItemsCollection,这样当添加项目时,我可以使用控件的ui来做任何我想要的事情。
这应该不难。我做错了什么?
【问题讨论】:
标签: c# winforms uitypeeditor collectioneditor