If have a property on an object that is another object with sub properties, if that top level property is changed to another object the sub properties for the new object are not created. This may seem a bit confusing so here is a sample of what I mean:
I have three classes, assume they all correctly implement the INotifyPropertyChanged interface.
[TypeConverter(typeof(ExandableObjectConverter)]
public class Parent
{
public object Child { get; set; }
}
[TypeConverter(typeof(ExandableObjectConverter)]
public class Child
{
public string Name { get; set; }
}
[TypeConverter(typeof(ExandableObjectConverter)]
public class OtherChild
{
public string OtherName { get; set; }
}
The SelectedObject of the PropertyGrid is an instance of type Parent, and the Child property is set to and instance of type Child. The type converter correctly creates the sub property of Name in the PropertyGrid. If somewhere in my code I change the Child property to an instance of type OtherChild...
parent.Child = new OtherChild();
I would expect the PropertyGrid to then update the sub properties and display the OtherName property in the PropertyGrid. However this does not happen unless you execute the Reload command, which seems a little over the top.
The other way I have found to fix this is by adding a couple of lines to the ComponentValueChanged method of the PropertyItem to re-create the sub properties.
If have a property on an object that is another object with sub properties, if that top level property is changed to another object the sub properties for the new object are not created. This may seem a bit confusing so here is a sample of what I mean:
I have three classes, assume they all correctly implement the INotifyPropertyChanged interface.
The SelectedObject of the PropertyGrid is an instance of type Parent, and the Child property is set to and instance of type Child. The type converter correctly creates the sub property of Name in the PropertyGrid. If somewhere in my code I change the Child property to an instance of type OtherChild...
I would expect the PropertyGrid to then update the sub properties and display the OtherName property in the PropertyGrid. However this does not happen unless you execute the Reload command, which seems a little over the top.
The other way I have found to fix this is by adding a couple of lines to the ComponentValueChanged method of the PropertyItem to re-create the sub properties.
I'm not sure if this is the correct fix, or if there are any other work arounds that I am missing. Any comments would be helpful.