加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何使用类作为属性

发布时间:2020-12-15 08:37:29 所属栏目:百科 来源:网络整理
导读:我尝试使用类作为属性,但我不能在“属性”选项卡中更改它的子属性 我想创建一个类似Font属性的属性 在这幅图片中 解决方法 您需要使用[TypeConverter(typeof(ExpandableObjectConverter))]来装饰它以获取要在编辑器中显示的子属性. public struct MyStruct{
我尝试使用类作为属性,但我不能在“属性”选项卡中更改它的子属性

我想创建一个类似Font属性的属性
在这幅图片中

解决方法

您需要使用[TypeConverter(typeof(ExpandableObjectConverter))]来装饰它以获取要在编辑器中显示的子属性.
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();
}

现在,这些属性可以扩展.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读