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

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

在这个例子中,FactoredAreaMod可以编辑,但两者都有elipsis,这会引起用户的极大混淆。有什么办法可以解决这个问题吗?

有帮助吗?

解决方案

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

此外,您应该应用编辑属性类型而不是属性。如果您不希望该属性可编辑,则将其应用于属性是没有收获的。

其他提示

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

最大的问题是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 { ... }

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

public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
  return context.PropertyDescriptor.IsReadOnly 
          ? UITypeEditorEditStyle.None 
          : UITypeEditorEditStyle.Modal;       
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top