Designer Property | List with name and value

787 Views Asked by At

First of all what I did (easier to explain what I want to get):

I've created a simple user control with a designer property of type List<bool>.

[Browsable(true)]
[Description("Select some.")]
[Category("SelectionTest")]
public List<bool> BoolList = new List<bool>();

When dragging this control onto my form and inspecting the designer I get this:

enter image description here

This one will open an editor:

enter image description here

Goal:

I would like to add another property of type string so it gets shown as the display-text on the left side. I dont care if it's editable.

So in general I would need something like List<string, bool> which isn't possible, i know. Unfortunately Dictionary and Tuple arn't working. When opening the editor, it will be still a single value shown as Value: (string, bool).

Anyone got an idea how to get another property into the right window or change the descriptions of the bools?

Would really appreciate every help in here. I guess this would be very nice knowledge to have. Think about the possibilities...

Thanks!

1

There are 1 best solutions below

2
On BEST ANSWER

I understand that you want named booleans

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";
    }
}

looks like:

looks like