我的属性网格中有两个类型相同的字段。但是,一个是只读的,另一个是可编辑的。
这两个字段都是自定义类型,因此都有一个自定义UITypeEditor,它将省略号(...)按钮在场地上。
[
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,但两者都有省略号,这会给用户造成很大的混淆。有什么办法把它关掉吗??
发布于 2009-03-05 21:24:35
使用ReadOnly属性。这将其标记为设计时只读,同时使其保持读/写状态以供运行时使用。
此外,还应将Editor特性应用于类型而不是属性。如果您不希望某个属性是可编辑的,则将其应用于该属性没有任何好处。
发布于 2009-03-05 21:55:03
多亏了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 { ... }发布于 2014-01-17 07:25:37
诀窍是,当有界属性为只读时,不要使用Modal样式。幸运的是,上下文是在GetEditStyle方法中提供的。一个简单的代码就可以完成这项工作:
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return context.PropertyDescriptor.IsReadOnly
? UITypeEditorEditStyle.None
: UITypeEditorEditStyle.Modal;
}https://stackoverflow.com/questions/616671
复制相似问题