読み取り専用のカスタムUITypeEditorの省略記号を削除するにはどうすればよいですか?
-
03-07-2019 - |
質問
プロパティグリッドに同じタイプの2つのフィールドがあります。ただし、一方は読み取り専用で、もう一方は編集可能です。
これらのフィールドは両方ともカスタムタイプであるため、フィールドに省略記号([...])ボタンを配置するカスタム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を編集できますが、両方に省略記号があり、ユーザーとの大きな混乱を引き起こします。それをオフにする方法は??
他のヒント
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 { ... }
バウンドプロパティが読み取り専用の場合、Modalスタイルを使用しないのがコツです。幸いなことに、コンテキストはGetEditStyleメソッドで提供されます。簡単なコードで仕事をします:
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return context.PropertyDescriptor.IsReadOnly
? UITypeEditorEditStyle.None
: UITypeEditorEditStyle.Modal;
}
所属していません StackOverflow