Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1735
Customizing Expandable Properties
posted

Hi.

I have a list-based property that I want to display in the xamPropertyGrid. I want to display it as read-only, i.e. I don't want the option to add/remove items to the list using the property grid. I also want to cutomize the way the items are presented in the property grid.

I have played around with the corresponding sample (xamPropertyGrid->Display->Customizing Expandable Properties) in the Samples Browser, but the current sample does not give me exactly what I want. Attached is an annotated screenshot from the Samples Browser. I have the following questions:

1. How to configure/remove the text displayed withing the red ellipse?

2. How to remove the minus-signs displayed within the blue ellipse at the right edge?

Regarding question 2, I have tried to set the property to read-only using the ReadOnly attribute, but that does not help. If I set the property to return e.g. a IReadOnlyList the minus signs do go away. However, I then have trouble getting my type descriptors to work to e.g. modify the default item labels to someting else than '[0]', '[1]' etc.

Regards,
Leif

Parents
No Data
Reply
  • 34510
    Offline posted

    Hi Leif,

    1.) This can be changed with a TypeConverter.  You can create your own custom TypeConverter and then use the TypeConverter attribute on your employees list property.  In the custom TypeConverter, override the ConvertTo method and have it return the desired text.

    public class MyListTypeConverter : TypeConverter
    {
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            return "Text Goes Here";
        }
    }
    
    [TypeConverter(typeof(MyListTypeConverter))]
    public List<Employee> Employees { get; set; }

    2.) Try returning a ReadOnlyCollection<T> from your property rather than just an IReadOnlyList.  I used a ReadOnlyCollection<T> and the property grid got rid of the minus buttons.

Children