Automaticly Expand Objects

Mar 29, 2011 at 11:27 AM

I try to use Property Editor for display properties of a class. I have one problem about deeply object inside the class

For example





Authors is showed like System.Collections.Generic.List`1[System.String],

I think because is a sub sub property, is possible to expand multi level objects? I defined DataTemnplate for different objects at different levels but still stops at level 1


Thanks in advance

Apr 2, 2011 at 11:27 AM

The PropertyEditor control does not currently have support for expanding properties. But this can be done by implementing custom editors. I would use a data grid or an ItemsControl to edit the list of strings. First create a DataTemplate


<DataTemplate x:Key="AuthorListEditor">
    <Expander Header="Edit authors">
            <ItemsControl ItemsSource="{Binding Value}">
                    <DataTemplate DataType="{x:Type local:Author}">
                        <TextBox Text="{Binding Name}"/>
            <Button Content="Add author" Command="{Binding Value.Add}"/>


and then register the custom type editor:

<pt:PropertyEditor SelectedObject="{Binding SelectedBook}" >
        <pt:TypeEditor EditedType="{x:Type local:AuthorList}" EditorTemplate="{StaticResource AuthorListEditor}"/>

I changed your model a little bit to simplify this example:

public enum SortOrder { Sorted, NotSorted };

public class Author
    public string Name { get; set; }

public class AuthorList : ObservableCollection<Author>
    public ICommand AddAuthor { get; set; }

    public AuthorList()
        AddAuthor = new DelegateCommand(() => this.Add(new Author()), () => Count < 5);

public class Book
    public AuthorList Authors { get; set; }
    public bool Group { get; set; }
    public bool Show { get; set; }
    public SortOrder SortOrder { get; set; }

    public Book()
        Authors = new AuthorList
                            new Author {Name = "William Shakespeare"},
                            new Author {Name = "Agatha Christie"}

Hope this helps, see the example I just checked into Examples/PropertyEditor/ExampleBrowser/Pages/CollectionExample.