如何删除只读的自定义UITypeEditor的省略号?

时间:2022-04-07 05:35:31

I have two fields that are of the same type in my property-grid. However, one is read-only, the other is editable.

我的属性网格中有两个相同类型的字段。但是,一个是只读的,另一个是可编辑的。

Both of these fields are of a custom type, and thus have a custom UITypeEditor, which puts the elipsis ([...]) button on the field.

这两个字段都是自定义类型,因此具有自定义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 { ... }

In this example, FactoredAreaMod is available to be edited, but BOTH have the elipsis, which will cause great confusion with the users. Any way to turn that off??

在这个例子中,FactoredAreaMod可以编辑,但两个都有elipsis,这将导致与用户的混淆。有什么方法可以把它关掉?

3 个解决方案

#1


Use the ReadOnly attribute. This marks it as design-time read-only while keeping it read/write for runtime use.

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

Also, you should either apply the Editor attribute to the type rather than the properties. There's no gain in applying it to a property if you don't want that property to be editable.

此外,您应该将Editor属性应用于类型而不是属性。如果您不希望该属性可编辑,则将其应用于属性没有任何好处。

#2


Thanks to Jeff Yates, I came up with an alternate solution. Here's how I solved it...

感谢Jeff Yates,我提出了另一种解决方案。这就是我解决它的方式......

The biggest issue was that the EditorAttribute was actually assigned in the FactoredAreaClass. I put it in the raw example just to show that there was an editor attribute assigned.

最大的问题是EditorAttribute实际上是在FactoredAreaClass中分配的。我把它放在原始示例中只是为了表明已经分配了编辑器属性。

[
    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


The trick is not to use the Modal style when the bounded property is readonly. Luckily for us, the context is provided in the GetEditStyle method. A simple code will do the job:

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

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

#1


Use the ReadOnly attribute. This marks it as design-time read-only while keeping it read/write for runtime use.

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

Also, you should either apply the Editor attribute to the type rather than the properties. There's no gain in applying it to a property if you don't want that property to be editable.

此外,您应该将Editor属性应用于类型而不是属性。如果您不希望该属性可编辑,则将其应用于属性没有任何好处。

#2


Thanks to Jeff Yates, I came up with an alternate solution. Here's how I solved it...

感谢Jeff Yates,我提出了另一种解决方案。这就是我解决它的方式......

The biggest issue was that the EditorAttribute was actually assigned in the FactoredAreaClass. I put it in the raw example just to show that there was an editor attribute assigned.

最大的问题是EditorAttribute实际上是在FactoredAreaClass中分配的。我把它放在原始示例中只是为了表明已经分配了编辑器属性。

[
    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


The trick is not to use the Modal style when the bounded property is readonly. Luckily for us, the context is provided in the GetEditStyle method. A simple code will do the job:

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

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