我继承了PropertyDescriptor类以提供某种“动态”属性。我正在向PropertyDescriptor添加一些属性。这工作得很好。
在PropertyGrid中显示对象时,ReadOnlyAttribute可以工作,但是EditorAttribute不能工作!
internal class ParameterDescriptor: PropertyDescriptor {
//...
public ParameterDescriptor(/* ... */) {
List<Attribute> a = new List<Attribute>();
string editor = "System.ComponentModel.Design.MultilineStringEditor,System.Design";
//...
a.Add(new ReadOnlyAttribute(true)); // works
a.Add(new DescriptionAttribute("text")); // works
a.Add(new EditorAttribute(editor, typeof(UITypeEditor))); // doesn't work!
//...
this.AttributeArray = a.ToArray();
}
}显示的对象使用继承的TypeConverter。
public class ParameterBoxTypeConverter: TypeConverter {
public override bool GetPropertiesSupported(ITypeDescriptorContext context) {
return true;
}
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) {
List<PropertyDescriptor> desc = new List<PropertyDescriptor>();
//...
ParameterDescriptor d = new ParameterDescriptor(/* ... */);
desc.Add(d);
//....
return new PropertyDescriptorCollection(desc.ToArray());
}我被困住了,因为PropertyGrid根本没有显示任何东西(我希望有一个“.”按属性值计算)。而且似乎没有办法进行调试!
那我怎么才能找到这里出了什么问题?
有办法调试到PropertyGrid等吗?
发布于 2013-07-29 09:21:55
从几个快速测试中,这个名称需要被定义为:
const string name = "System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
attribs.Add(new EditorAttribute(name, typeof(UITypeEditor)));在内部,它使用Type.GetType,并且:
var type1 = Type.GetType("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
// ^^^ not null
var type2 = Type.GetType("System.ComponentModel.Design.MultilineStringEditor, System.Design");
// ^^^ null当然,你可以用:
attribs.Add(new EditorAttribute(typeof(MultilineStringEditor), typeof(UITypeEditor)));或者,您可以override GetEditor并做您想做的任何事情。
https://stackoverflow.com/questions/17919881
复制相似问题