Skip to content

动态隐藏属性

如果一个属性在设计器中是否显示,需要受到其他一个或几个属性影响,可以通过重写 GetDesignerPropertyVisible 方法实现

C#示例代码

csharp
    public class MyPluginServerCommand : Command, ICommandExecutableInServerSideAsync
    {
        public bool EnableCache { get; set; }
        public int CacheTime { get; set; }
        public override bool GetDesignerPropertyVisible(string propertyName, CommandScope commandScope)
        {
            if (propertyName == nameof(CacheTime))
            {
                return EnableCache;
            }
            return base.GetDesignerPropertyVisible(propertyName, commandScope);
        }

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            return new ExecuteResult();
        }
        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }
    }

设计器效果

1670081989415-62d0705c-b6e9-4a96-9534-7fef341edb86.gif

更新: 2022-12-04 20:27:29
原文: https://www.yuque.com/robert-bh51n/ea8l6c/tc7ya7l1pg6pya1l