كيف يمكنني إزالة القطع لUITypeEditor مخصصة للقراءة فقط؟

StackOverflow https://stackoverflow.com/questions/616671

  •  03-07-2019
  •  | 
  •  

سؤال

ولقد اثنين من المجالات التي هي من نفس النوع في ملكيتي الشبكة. ومع ذلك، يتم قراءة واحدة فقط، والآخر هو للتحرير.

وكل من هذه المجالات هي من النوع المخصص، وبالتالي يكون لها 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، والتي سوف تسبب ارتباك كبير مع المستخدمين. بأي حال من الأحوال أن تتحول إلى قبالة ؟؟

هل كانت مفيدة؟

المحلول

واستخدم قراءة فقط السمة. ويمثل هذا أنها وقت التصميم للقراءة فقط مع الحفاظ على القراءة / الكتابة للاستخدام وقت التشغيل.

وبالإضافة إلى ذلك، يجب عليك إما تطبيق محرر السمة لنوع بدلا من الخصائص. ليس هناك ربح في تطبيقه على الخاصية إذا كنت لا تريد أن الخاصية لتكون قابلة للتحرير.

نصائح أخرى

وبفضل جيف ييتس، خطرت لي حل بديل. وإليك كيف حلها ...

وكانت أكبر مشكلة أن 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 { ... }

والحيلة ليست لاستخدام أسلوب مشروط عند الخاصية يحدها هي للقراءة فقط. لحسن الحظ بالنسبة لنا، يتم توفير السياق في طريقة GetEditStyle. وهناك رمز بسيط قيام بهذه المهمة:

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