我在自定义控件中实现了StringCollection编辑器,下面是代码:
[Description("extra free-form attributes on this thing.")]
[Editor(@"System.Windows.Forms.Design.StringCollectionEditor," +
"System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
typeof(System.Drawing.Design.UITypeEditor))]
public System.Collections.Specialized.StringCollection Items
{
get
{
if (items == null)
items = new System.Collections.Specialized.StringCollection();
return this.items;
}
}
public System.Collections.Specialized.StringCollection items;
这很好但每次我在集合中输入一些值并重新打开它时......值会丢失,即它不会存储值。
是否缺少用于存储用户输入字符串值的内容,或者我是否需要实现自定义StringCollection,以便用户在字符串编辑器中输入字符串值。
我甚至提到下面给出的链接..但仍存在问题: How can I use a WinForms PropertyGrid to edit a list of strings?
答案 0 :(得分:1)
是的,您需要将DesignerSerializationVisibility属性应用于DesignerSerializationVisibility.Content
。如果不这样做,对复杂对象(除了原语,字符串等)的所有更改都将丢失。
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Description("extra free-form attributes on this thing.")]
[Editor(@"System.Windows.Forms.Design.StringCollectionEditor," +
"System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
typeof(System.Drawing.Design.UITypeEditor))]
public System.Collections.Specialized.StringCollection Items
{
get
{
if (items == null)
items = new System.Collections.Specialized.StringCollection();
return this.items;
}
}
答案 1 :(得分:0)
您也可以尝试在构造函数中创建列表。这与字符串集合编辑器和DesignerSerializationVisibility属性一起适用于我。
UITableViewCell