首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何删除只读的自定义UITypeEditor的省略号?

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

Stack Overflow用户
提问于 2009-03-05 21:20:50
回答 3查看 1K关注 0票数 1

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

这两个字段都是自定义类型,因此都有一个自定义UITypeEditor,它将省略号(...)按钮在场地上。

代码语言:javascript
复制
[
     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,但两者都有省略号,这会给用户造成很大的混淆。有什么办法把它关掉吗??

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-03-05 21:24:35

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

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

票数 1
EN

Stack Overflow用户

发布于 2009-03-05 21:55:03

多亏了Jeff Yates,我想出了一个替代方案。这就是我是如何解决这个问题的。

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

代码语言:javascript
复制
[
    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 { ... }
票数 1
EN

Stack Overflow用户

发布于 2014-01-17 07:25:37

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

代码语言:javascript
复制
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
  return context.PropertyDescriptor.IsReadOnly 
          ? UITypeEditorEditStyle.None 
          : UITypeEditorEditStyle.Modal;       
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/616671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档