我有一个带有 SelectedObject 类型对象的 PropertyGrid class1
。
我正在实现对象的ICustomTypeDescriptor
接口class1
,并且我PropertyDescriptorCollection
从另一个对象中获取一个class2
,并且需要class2
PropertyDescriptors
在 PropertyGrid 和class1
PropertyDescriptors
.
我在 PropertyGrid 中显示以下错误class2
PropertyDescriptors
:
对象与目标类型不匹配。
这是我的代码,无需class2
PropertyDescriptors
:
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection propertyDescriptorCollection = TypeDescriptor.GetProperties(this);
var propertyDescriptors = new List<PropertyDescriptor>();
for (int i = 0; i < propertyDescriptorCollection.Count; i++)
{
propertyDescriptors.Add(propertyDescriptorCollection[i]);
}
return new PropertyDescriptorCollection(propertyDescriptors.ToArray());
}
这是我正在处理的代码:
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection propertyDescriptorCollection = TypeDescriptor.GetProperties(this);
var propertyDescriptors = new List<PropertyDescriptor>();
for (int i = 0; i < propertyDescriptorCollection.Count; i++)
{
propertyDescriptors.Add(propertyDescriptorCollection[i]);
}
var class2PropertyDescriptorCollection = TypeDescriptor.GetProperties(class2);
for (int i = 0; i < class2PropertyDescriptorCollection.Count; i++)
{
propertyDescriptors.Add(class2PropertyDescriptorCollection[i]);
}
return new PropertyDescriptorCollection(propertyDescriptors.ToArray());
}
当from显示在 PropertyGrid 中时,如何显示PropertyDescriptors
from ?class2
PropertyDescriptors
class1