M4rsha11X
M4rsha11X

Reputation: 97

How To Use Class As Property

I tried using class as a property but I can't change it's sub properties in the "Properties Tab"

I want to make a property like the Font property in this picture

Upvotes: 6

Views: 182

Answers (1)

Ron Beyer
Ron Beyer

Reputation: 11273

You need to decorate it with [TypeConverter(typeof(ExpandableObjectConverter))] to get the sub-properties to show up in the editor.

public struct MyStruct
{
    public int One;
    public int Two;
    public int Three;
}

public class MyEditableClass : Control
{
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public MyStruct MyProperty { get; set; } = new MyStruct();
}

The properties will now be expandable.

Upvotes: 8

Related Questions