This project has moved. For the latest updates, please go here.

PropertyGrid validation for dynamic properties

Jan 15, 2015 at 2:26 PM
I know the word 'dynamic' is probably overloaded by now. What I mean is the object that I am assigning to PropertyGrid.SelectedObject implements ICustomTypeProvider and based on one or more property values at runtime, other properties will be added dynamically. The only way I've been able to get the current PropertyGrid implementation to adjust to new (or removed) properties is to:

_propertyGrid.SelectedObject = null
_propertyGrid.SelectedObject = myObject

Now this seems to work fine and dandy, BUT I'm also trying to take advantage of .Net 4.5 validation, particularly INotifyDataErrorInfo interface.

By default Binding.ValidatesOnNotifyDataErrors is set to true in 4.5.

Now, when a property has been added to the SelectedObject, and the little switcheroo above is executed, I see PropertyItem.OnCoerceValueChanged get called, particularly the line:

Validation.MarkInvalid(be, errors[0]);

So I know the PropertyItem's binding has been manually marked with an validation error.

But I never see the validation visual show up.

If I manually invalidate a different property, i.e. blank out a required textbox and tab away, I see the same Validation.MarkInvalid code fire, but I do then see the nice red visual around the PropertyItem.

Any ideas? Thanks!