This project is read-only.

Expandable Collections

Aug 11, 2010 at 5:58 PM
Edited Aug 12, 2010 at 12:38 AM
I've just started using this. Is there a way to get collections (Lists specifically) to expand to show their members? The only thing that shows up is the List type "System.Collections.Generic.List`1[System.Int32]"

Here is example of what I'm trying to do.


[TypeConverterAttribute(typeof(ExpandableObjectConverter))]
public class Foo
{
 public Foo()
  {
   X = 3.14f;
   Y = 1.29f;

   IntList = new List<int>();
   IntList.Add(1);
   IntList.Add(2);
   IntList.Add(3);
  }

  public float X { get; set; }
  public float Y { get; set; }

   public List<int> IntList { get; set; }
 }

 public class Bar
 {
  public Bar()
  {
   F = new Foo();
   B = true;
  }

 public Foo F { get; set; }
 public bool B { get; set; }
 }

 Bar myBar;

 private void button_Click(object sender, RoutedEventArgs e)
 {
  myBar = new Bar();
  myGrid.Instance = myBar;
 }
Aug 13, 2010 at 12:30 AM
Edited Aug 13, 2010 at 9:43 PM

Still looking at this - looks like the IList datatemplate just shows the string - looking at how to expand functionality...

Actually - I don't think it is getting hit - if I replace ListBox with a TextBox, that says "Hello" nothing changes...

 

    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr3:ObservableCollection}}">
        <!--<ListBox ItemsSource="{Binding Path=Value}"/>-->
        <TextBox>Hello</TextBox>
    </DataTemplate>

Mar 15, 2011 at 11:01 AM

I want a DataTemplate for ObservableCollection in there is a Button in their.

 

But their always come a mistake that it doesn´t find ObservableCollection.

xmlns:clr3="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr3:ObservableCollection}}">
      <Button Content="..."/>
 </DataTemplate>

What is my mistake?

Coordinator
Mar 15, 2011 at 12:17 PM
Edited Mar 15, 2011 at 12:17 PM

Datatemplates for generic Types normaly don't work.

 

Look at PropertyTemplateSelector.cs with the Line 

if (!(property.PropertyType is String) && property.PropertyType is IEnumerable)                
 propertyType = typeof(List<object>);

I added support for the

     <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type generics:List`1[System.Object]}}">
<TypeEditors:CollectionEditorControl NumerableType="{Binding Path=PropertyType}" NumerableValue="{Binding Path=Value}" MyProperty="{Binding}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></TypeEditors:CollectionEditorControl>
</DataTemplate>