简体   繁体   中英

Change property grid collection display

How can I change the (Collection) text displayed on the right column for a collection property in a property grid?

在此处输入图片说明

You can use a TypeConverterAttribute with a custom TypeConverter , something like this:

public class Sample
{
    public Sample()
    {
        Ints = new List<int>();
    }

    [TypeConverter(typeof(MyConverter))]
    public List<int> Ints { get; }
}

public class MyConverter : TypeConverter
{
    public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
    {
        if (destinationType == typeof(string))
            return "Hello world";

        return base.ConvertTo(context, culture, value, destinationType);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM