Вам необходимо создать конвертер типов, а затем применить его с помощью атрибута к классу AgeWrapper. Затем сетка свойств будет использовать этот конвертер типов для отображения отображаемой строки. Создайте конвертер типов вот так ...
public class AgeWrapperConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context,
Type destinationType)
{
// Can always convert to a string representation
if (destinationType == typeof(string))
return true;
// Let base class do standard processing
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture,
object value,
Type destinationType)
{
// Can always convert to a string representation
if (destinationType == typeof(string))
{
AgeWrapper wrapper = (AgeWrapper)value;
return "Age is " + wrapper.Age.ToString();
}
// Let base class attempt other conversions
return base.ConvertTo(context, culture, value, destinationType);
}
}
Обратите внимание, что он наследуется от ExpandableObjectConverter. Это связано с тем, что класс AgeWrapper имеет дочернее свойство AgeWrapper.Age, которое необходимо отображать, располагая кнопку + рядом с записью AgeWrapper в сетке. Если у вашего класса нет дочерних свойств, которые вы хотели бы предоставить, то вместо этого наследуйте от TypeConverter. Теперь примените этот конвертер к своему классу ...
[TypeConverter(typeof(AgeWrapperConverter))]
public class AgeWrapper