This project has moved and is read-only. For the latest updates, please go here.

DoubleCollection & PrimitiveTypeCollectionEditor

Oct 9, 2013 at 7:48 PM
Good day.

in code:

public class PrimitiveTypeCollectionEditor : TypeEditor<PrimitiveTypeCollectionControl>
    protected override void ResolveValueBinding(PropertyItem propertyItem)
        base.Editor.ItemsSourceType = propertyItem.PropertyType;
        base.Editor.ItemType = propertyItem.PropertyType.GetGenericArguments()[0];

In line

base.Editor.ItemType = propertyItem.PropertyType.GetGenericArguments()[0];

appear exception in case of setting in SelectedObject of PropertyGrid object with property type of DoubleCollection.

in this case propertyItem.PropertyType.GetGenericArguments() return System.Type[0] - empty array and element with index 0 is absent, therefor exception is appears.

I can fix it by making user Type Editor, but I think that it not correct that unrouted exception is appear.

Thanks for answer.

P.S. example of xaml code:

<Window x:Class="testwpf.MainWindow"
    Title="MainWindow" Height="350" Width="525">
    <xctk:PropertyGrid Name="pg" SelectedObject="{Binding ElementName=rect1}"/>           

    <Rectangle Width="100" Height="100" Fill="Yellow" Name="rect1"/>
Oct 10, 2013 at 2:22 PM

DoubleCollection is not managed by the PrimitiveTypeCollectionEditor.

As a workaround, you can add a check for DoubleCollection :
else if( type == typeof( DoubleCollection ) )
        Editor.ItemType = typeof( double );
But this would not encapsulate Int32Collection, .....

Issue has been created.
Oct 12, 2013 at 11:32 AM
Can you say to me if this is working:

protected override void ResolveValueBinding( PropertyItem propertyItem )
  Editor.ItemsSourceType = propertyItem.PropertyType;

  var icollection = propertyItem.PropertyType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection<>));
  if (icollection != null)
      Editor.ItemType = icollection.GetGenericArguments()[0];
    Editor.ItemType = propertyItem.PropertyType.GetGenericArguments()[0];
  base.ResolveValueBinding( propertyItem );

then I will implement it in my fork on github (
Oct 26, 2013 at 3:37 PM
I#ve now tested it, and implemented it on my fork at github