类列表的 C# 属性
我正在尝试在 Visual Studio 设计器中使用属性网格。
我有一个类列表,我希望开发人员能够在设计时添加这些类,以便用户可以访问额外的功能。
这是我已经在代码中使用的一些示例代码。问题是,当开发人员进入设计模式时,他只能看到列表中有 x 个值,但看不到任何细节。当尝试将新项目添加到列表时,用户会收到错误消息。
未找到类型“EditorTextBox+SyntaxRegex”的构造函数。
现在的代码:
private List<SyntaxRegex> _syntaxRegexList = new List<SyntaxRegex>();
public class SyntaxRegex
{
public string title;
public string regex;
public Color color;
}
Public List<SyntaxRegex> SyntaxRegexList
{
get{_syntaxRegexList = value;}
set{return _regexList;}
}
I'm trying to use the property grid in the designer for Visual Studio.
I have a list of classes that I want the developer to be able to add to at design time so that the user can have access to extra features.
Here is some example code of what I have in the code already. The problem is when the developer goes to the design mode he can only see that there are x number of values in the list, but is unable to see any of the details. When trying to add a new item to the list the user is presented with an error.
Constructor on type 'EditorTextBox+SyntaxRegex' not found.
Now the code:
private List<SyntaxRegex> _syntaxRegexList = new List<SyntaxRegex>();
public class SyntaxRegex
{
public string title;
public string regex;
public Color color;
}
Public List<SyntaxRegex> SyntaxRegexList
{
get{_syntaxRegexList = value;}
set{return _regexList;}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加类型转换器/编辑器;一个好的开始是
在每个
class
定义上方添加:。例如,以下内容可以正常工作(请注意,我更改为属性,删除了列表设置器等):具体的错误消息还让我想知道您的实际类型是否是带有公共无参数构造函数的公共类型(它无法编译的事实让我怀疑你还没有发布实际的代码......)
You need to add type converters / editors; a good start would be to add:
above each
class
definition. For example, the following works fine (note I changed to properties, removed the list setter, etc):The specific error message also makes me wonder if your actual type is public with a public parameterless constructor (the fact that it doesn't compile makes me suspect you haven't posted the actual code...)