设计师 属性 |包含名称和值的列表
Designer Property | List with name and value
首先我做了什么(更容易解释我想要得到什么):
我使用类型为 List<bool>
的设计器 属性 创建了一个简单的用户控件。
[Browsable(true)]
[Description("Select some.")]
[Category("SelectionTest")]
public List<bool> BoolList = new List<bool>();
将此控件拖到我的窗体上并检查设计器时,我得到:
这将打开一个编辑器:
目标:
我想添加另一个 string
类型的 属性,以便它显示为左侧的显示文本。我不在乎它是否可编辑。
所以一般来说,我需要像 List<string, bool>
这样的东西,我知道这是不可能的。不幸的是 Dictionary
和 Tuple
不工作。当打开编辑器时,它仍然是单个值,显示为 Value: (string, bool)
.
有人知道如何让另一个 属性 进入正确的 window 或更改布尔值的描述吗?
非常感谢这里的每一个帮助。我想这将是非常好的知识。想想可能性...
谢谢!
我知道你想要命名布尔值
public partial class UserControl1 : UserControl
{
[Browsable(true)]
[Description("Select some.")]
[Category("Selection Test"), DisplayName("Bool List")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<BoolProperty> BoolList { get; set; } = new List<BoolProperty>();
public UserControl1()
{
InitializeComponent();
}
}
[Serializable]
public class BoolProperty
{
public string Name { get; set; }
public bool Value { get; set; }
public override string ToString()
{
return Name ?? "Empty Boolean Property";
}
}
看起来像:
首先我做了什么(更容易解释我想要得到什么):
我使用类型为 List<bool>
的设计器 属性 创建了一个简单的用户控件。
[Browsable(true)]
[Description("Select some.")]
[Category("SelectionTest")]
public List<bool> BoolList = new List<bool>();
将此控件拖到我的窗体上并检查设计器时,我得到:
这将打开一个编辑器:
目标:
我想添加另一个 string
类型的 属性,以便它显示为左侧的显示文本。我不在乎它是否可编辑。
所以一般来说,我需要像 List<string, bool>
这样的东西,我知道这是不可能的。不幸的是 Dictionary
和 Tuple
不工作。当打开编辑器时,它仍然是单个值,显示为 Value: (string, bool)
.
有人知道如何让另一个 属性 进入正确的 window 或更改布尔值的描述吗?
非常感谢这里的每一个帮助。我想这将是非常好的知识。想想可能性...
谢谢!
我知道你想要命名布尔值
public partial class UserControl1 : UserControl
{
[Browsable(true)]
[Description("Select some.")]
[Category("Selection Test"), DisplayName("Bool List")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<BoolProperty> BoolList { get; set; } = new List<BoolProperty>();
public UserControl1()
{
InitializeComponent();
}
}
[Serializable]
public class BoolProperty
{
public string Name { get; set; }
public bool Value { get; set; }
public override string ToString()
{
return Name ?? "Empty Boolean Property";
}
}
看起来像: