Mig*_*elo 4 .net typeconverter .net-3.5 windows-forms-designer winforms
我想知道 .Net-3.5 是否带有内置的List<string>
or string[]
TypeConverter
,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;
}
}
Run Code Online (Sandbox Code Playgroud)
选项 2 - 自定义集合编辑器
首先创建自定义编辑器:
//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;
}
}
Run Code Online (Sandbox Code Playgroud)
然后使用 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;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2213 次 |
最近记录: |