Datagrid cell values from property descriptor

Dec 2, 2009 at 6:28 PM

I have a simple data grid that I am binding to an ObservableCollection<> of objects. These objects have two string properties. I have defined and registered a type description provider, implemented a custom type descriptor, and custom property descriptor for these objects.

At runtime, when I set AutoGenerateColumns="True" it successfully calls the GetProperties() on my type descriptor and returns back a PropertyDescriptorCollection with 3 property descriptors (2 ReflectPropertyDescriptors for the 2 string properties defined on the class and 1 custom property descriptor that I added). So far so good - the columns do in fact get auto-generated and the column header properly reflects the property descriptor name.

However, the GetValue() method on the custom property descriptor never gets called. Consequently, the column for the custom property descriptor has no data.

Do I have to do something extra to get it to use the property descriptor's data?

Thanks for any input or suggestions.

Dec 30, 2009 at 3:01 AM


I am having the same exact problem.  I was able to get the datagrid to show the values, but at the cost of the correct column names which may point to the underlying problem in the datagrid.  When I change my PropertyDescriptor to have a display name that equals the column number it displays the values.  However my column headers are now 0,1,2 etc.  I might poke around the source to see what the problem might be.


Jul 15, 2010 at 8:28 PM

I had a similar issue, and the following post about "Binding and Custom Type Descriptors" (you have to scroll down a bit) helped me:  Essentially, the solution that worked for me was to have my data object implement ICustomTypeDescriptor rather than registering a type description provider.  The ICustomTypeDescriptor interface exposes a GetProperties() method that returns a PropertyDescriptorCollection object.  By implementing this interface, you can return a PropertyDescriptorCollection object that contains your custom PropertyDescriptors, and WPF will use them.  This behavior actually seems to be embedded in the WPF data binding framework rather than in the DataGrid itself.