Using the PropertyGrid control, if one of the properties is of type List<T> ou T[], where T is a primitve type, the user can enter the values he wants, but they get lost. I found a fix, at least for collections of type List<T>:
Change PrimitiveTypeCollectionEditor.cs, ResolveValueBinding() to:
{
var type = propertyItem.PropertyType;
Editor.ItemsSourceType = type;
if (type.BaseType == typeof(System.Array))
{
Editor.ItemType = type.GetElementType();
}
else // if (type.ContainsGenericParameters)
{
Editor.ItemType = type.GetGenericArguments()[0];
}
base.ResolveValueBinding( propertyItem );
}
}
Change PrimitiveTypeCollectionControl.cs, ComputeItemsSource() to:
{
if (ItemsSource == null)
{
string tt = Text;
ItemsSource = CreateItemsSource();
Text = tt;
}
return ItemsSource;
}
NB: This last change is necessary not to loose the value when the collection object needs to be created. Otherwise, the OnTextChanged event is called when the collection object gets created, and the desired content gets lost.
Change PrimitiveTypeCollectionEditor.cs, ResolveValueBinding() to:
{
var type = propertyItem.PropertyType;
Editor.ItemsSourceType = type;
if (type.BaseType == typeof(System.Array))
{
Editor.ItemType = type.GetElementType();
}
else // if (type.ContainsGenericParameters)
{
Editor.ItemType = type.GetGenericArguments()[0];
}
base.ResolveValueBinding( propertyItem );
}
}
Change PrimitiveTypeCollectionControl.cs, ComputeItemsSource() to:
{
if (ItemsSource == null)
{
string tt = Text;
ItemsSource = CreateItemsSource();
Text = tt;
}
return ItemsSource;
}
NB: This last change is necessary not to loose the value when the collection object needs to be created. Otherwise, the OnTextChanged event is called when the collection object gets created, and the desired content gets lost.