我想知道.Net-3.5 是否带有内置的List<string>
或string[]
TypeConverter
或UITypeEditor
以便我可以从属性网格中编辑这种属性。
问问题
2321 次
2 回答
5
UITypeEditor 用于List<String>
因为string[]
你不需要做任何特别的事情,属性网格将使用一个包含多行文本框的标准对话框来编辑字符串数组,每一行都是数组中的一个元素。
要List<string>
在属性网格中进行编辑,您可以使用以下任一选项:
StringCollectionEditor
它显示了一个对话框,其中包含一个用于编辑元素的多行文本框- 创建自定义
CollectionEditor
以在集合编辑器对话框中编辑项目
选项 1 - StringCollectionEditor
private List<string> myList = new List<string>();
[Editor("System.Windows.Forms.Design.StringCollectionEditor, " +
"System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<string> MyList {
get {
return myList;
}
set {
myList = value;
}
}
选项 2 - 自定义 CollectionEditor
首先创建自定义编辑器:
//You need to add reference to System.Design
public class MyStringCollectionEditor : CollectionEditor {
public MyStringCollectionEditor() : base(type: typeof(List<String>)) { }
protected override object CreateInstance(Type itemType) {
return string.Empty;
}
}
然后用 editor 属性装饰属性:
private List<string> myList = new List<string>();
[Editor(typeof(MyStringCollectionEditor), typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<string> MyList {
get {
return myList;
}
set {
myList = value;
}
}
于 2018-06-17T10:49:16.823 回答
2
您可以使用 [Editor("System.Windows.Forms.Design.StringArrayEditor, System.Design, [此处的程序集版本和公钥令牌信息]", typeof(System.Drawing.Design.UITypeEditor))]
于 2010-01-29T15:48:26.167 回答