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
Returning a ReadOnlyCollection rather than an IReadOnlyList works as expected, i.e. the minus signs are gone.
I still can't get the TypeConverter to work as expected. I already use a TypeConverter as you suggest, and as it is done in the Samples Browser sample. However, the TypeConverter seems to be applied only initially before the collection is expanded in the property grid. The Samples Broswer sample has the same issue: Initially it displays the text 'Employee's Collection', as given by the type converter. As soon as the collection is expanded, the text changes to 'List, Count: 2' and stays that way event when the collection is collapsed.
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.