代码之家  ›  专栏  ›  技术社区  ›  Jerry

如何删除只读的自定义UITypeEditor的概要?

  •  1
  • Jerry  · 技术社区  · 17 年前

    这两个字段都是自定义类型,因此有一个自定义的UITypeEditor,它将elipsis([…])按钮放在字段上。

    [
         CategoryAttribute("5 - Wind"),
         DisplayName("Factored Area"),
         Description("The factored area for the segment."),
         EditorAttribute(typeof(umConversionTypeEditor), typeof(UITypeEditor)),
         TypeConverter(typeof(umConversionTypeConverter)),
         ReadOnly(true)
    ]
    public FactoredAreaClass FactoredArea { ... }
    
    [
         CategoryAttribute("5 - Wind"),
         DisplayName("Factored Area Modifier"),
         Description("The factored area modifier."),
         EditorAttribute(typeof(umConversionTypeEditor), typeof(UITypeEditor)),
         TypeConverter(typeof(umConversionTypeConverter))
    ]
    public FactoredAreaClass FactoredAreaMod { ... }
    

    3 回复  |  直到 17 年前
        1
  •  1
  •   Jeff Yates    17 年前

    使用 ReadOnly 属性。这将其标记为设计时只读,同时保持其读/写以供运行时使用。

    此外,您应该申请 Editor

        2
  •  1
  •   Jerry    9 年前

    最大的问题是EditorAttribute实际上是在FactoryAreaClass中分配的。我把它放在原始示例中只是为了显示分配了一个编辑器属性。

    [
        CategoryAttribute("5 - Wind"),
        DisplayName("Factored Area"),
        Description("The factored area for the segment."),
        EditorAttribute(typeof(UITypeEditor), typeof(UITypeEditor)), // RESET THE UITYPEEDITOR to "nothing"
        ReadOnly(true)
    ]
    public FactoredAreaClass FactoredArea { ... }
    
    [
        CategoryAttribute("5 - Wind"),
        DisplayName("Factored Area Modifier"),
        Description("The factored area modifier."),
        // the EditorAttribute and TypeConverter are part of FactoredAreaClass
    ]
    public FactoredAreaClass FactoredAreaMod { ... }
    
        3
  •  0
  •   John Silver    12 年前

    诀窍是当有界属性是只读的时,不要使用模态样式。幸运的是,上下文是在GetEditStyle方法中提供的。一个简单的代码就可以完成这项工作:

    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
      return context.PropertyDescriptor.IsReadOnly 
              ? UITypeEditorEditStyle.None 
              : UITypeEditorEditStyle.Modal;       
    }