Skip to content

折叠高级属性

此特性为活字格V10.0.0.0新增功能

当服务端命令属性特别多时,默认会在属性面板上显示服务端命令的所有属性。但是如果有一些属性不太常用,会大幅提高用户的学习成本。

通过标注AdvancedPropertyAttribute可以轻松解决这个问题。

设计时代码

csharp
    public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
    {
        public string MyProperty { get; set; }
        public string MyProperty1 { get; set; }

        [AdvancedProperty]
        [DefaultValue(null)]
        public string MyProperty2 { get; set; }

        [AdvancedProperty]
        [DefaultValue(null)]
        public string MyProperty3 { get; set; }

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }

        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }

设计器效果

1707116421112-4868f4ea-d6c3-405d-b06d-ea156ee5ca35.gif如果用户修改过高级属性中的值,选择服务端命令后,高级设置会自动展开,如果用户没有设置过任何高级属性中的值。选中服务端命令时,高级属性会默认折叠

折叠对象属性

设计时代码

csharp
    public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
    {
        [ObjectProperty(ObjType = typeof(MyObj))]
        public MyObj MyProperty { get; set; }

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }

        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }

    public class MyObj : ObjectPropertyBase
    {
        public string MyProperty { get; set; }
        public string MyProperty1 { get; set; }

        [AdvancedProperty]
        [DefaultValue(null)]
        public string MyProperty2 { get; set; }

        [AdvancedProperty]
        [DefaultValue(null)]
        public string MyProperty3 { get; set; }
    }

设计器效果

1707116740422-e5a31bb4-508e-45fe-9985-5a1f064e0567.png

折叠对象列表属性

设计时代码

csharp
    public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
    {
        [ObjectListProperty(ItemType = typeof(MyObj))]
        public List<INamedObject> MyProperty { get; set; }

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }

        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }

    public class MyObj : ObjectPropertyBase, INamedObject
    {
        public string Name { get; set; }
        public string MyProperty { get; set; }
        public string MyProperty1 { get; set; }

        [AdvancedProperty]
        [DefaultValue(null)]
        public string MyProperty2 { get; set; }

        [AdvancedProperty]
        [DefaultValue(null)]
        public string MyProperty3 { get; set; }
    }

设计器效果

1707116936250-e865a5d8-537e-48bd-8c67-f3568d468cd2.png

更新: 2024-02-05 15:11:43
原文: https://www.yuque.com/robert-bh51n/ea8l6c/fddy3yy8f1564m6f