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

DoubleCollection & PrimitiveTypeCollectionEditor

Oct 9, 2013 at 6: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];
        base.ResolveValueBinding(propertyItem);
    }
...

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"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    Title="MainWindow" Height="350" Width="525">
<Grid>        
    <xctk:PropertyGrid Name="pg" SelectedObject="{Binding ElementName=rect1}"/>           

    <Rectangle Width="100" Height="100" Fill="Yellow" Name="rect1"/>
</Grid>
</Window>
Developer
Oct 10, 2013 at 1:22 PM
Hi,

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 https://wpftoolkit.codeplex.com/workitem/20299 has been created.
Oct 12, 2013 at 10: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];
  }
  else
  {
    Editor.ItemType = propertyItem.PropertyType.GetGenericArguments()[0];
  }      
  base.ResolveValueBinding( propertyItem );
}

then I will implement it in my fork on github (https://github.com/jogibear9988/WpfExToolkit/commits/Extended)
Oct 26, 2013 at 2:37 PM
I#ve now tested it, and implemented it on my fork at github