what is ICustomTypeDescriptor and when to use it?

There are a lot of resources available that show different use cases for the ICustomTypeDescriptor interface, but in short, the typical use case is to provide custom type description outside of what the standard TypeDescriptor provides. The interface is rarely implemented without needing to return custom member descriptors such as a custom PropertyDescriptor.

The Type Descriptor Overview from the MSDN is a good resource which might help further clarify purpose and usage.


In MVVM you are supposed to create your ViewModels as plain C# classes exposing properties that can be bound to controls and possibly implementing INotifyPropertyChanged for issuing notifications when you change values of your properties so that the bound controls can take notice. WPF will use reflection to discover the properties of your ViewModel classes.

However, it is conceivable that you might not want WPF to use reflection for discovering properties on your objects. It is conceivable that your ViewModel might not even implement C# properties and instead it might expose named values using some other mechanism. For example, you might build a general-purpose ViewModel which dcontains an IDictionary<string,object> populated with named values. If ICustomTypeDescriptor did not exist, you would not be able to do this. ICustomTypeDescriptor tells WPF to refrain from using reflection to discover the properties of your ViewModel, and instead to discover them by invoking methods of your ICustomTypeDescriptor interface.

Further reading can be found here: https://docs.microsoft.com/en-us/archive/msdn-magazine/2005/april/net-matters-icustomtypedescriptor-part-1