出于好奇,想象一下您有这样一个UITypeEditor:
public class CustomEditor : System.Drawing.Design.UITypeEditor
{
public bool DoSomething { get; set; }
[...]
}您希望使用它来编辑DoSomething设置为true的属性之一。
public MyClass
{
[EditorAttribute(typeof(CustomEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string MyProperty { get; set; }
[...]
}在实例化编辑器时,如何为CustomEditor的CustomEditor属性指定一个值?这是可能的吗?还是必须创建继承CustomEditor的类与可能配置的数量一样多?
发布于 2014-10-24 08:47:33
在UITypeEditor.EditValue的实现中,您可以查看context参数以获得对正在编辑的属性的描述符的引用。然后,您可以查看另一个属性,在其中放置编辑器配置值。
public class CustomEditor : System.Drawing.Design.UITypeEditor
{
public override object EditValue(
ITypeDescriptorContext context,
IServiceProvider provider,
object value)
{
var property = context.PropertyDescriptor;
var config = (MyConfigAttribute)
property.Attributes[typeof(MyConfigAttribute)];
// ...
}
}https://stackoverflow.com/questions/26543819
复制相似问题