How to create Custom Editor Template

May 21, 2010 at 3:28 PM

As in the title: we need to create a Custom Editor Template in code-behind, NOT in XAML, does anyone can help us giving starting point or sample codes?

Thanks for your time, best regards.

May 21, 2010 at 11:20 PM

I think you could create a new PropertyTemplateSelector to achieve this, it is currently an internal property in the PropertyEditor class, but I can make it public...

May 26, 2010 at 11:24 AM

Thanks for your answer, but maybe I have asked a wrong question, and it shold be ok to do it in XAML.
Maybe it's better I explain my goal:
I would like to use PropertyEditor to edit a Point3DCollection, so that the user can edit the X,Y, and Z properties of every Point3D in the collection.
The best is to use a DataGrid. So, starting from the DatagridDemo project I have modified the code to have (follows cut&paste of relevant code ):


        <!-- defining the custom editor here -->
        <DataTemplate x:Key="DatagridEditor">
            <toolkit:DataGrid AutoGenerateColumns="True" ItemsSource="{Binding Value}"/>

<pe:PropertyEditor SelectedObject="{Binding MyCollection}" Margin="8" Name="propertyeditor">
<!-- custom editors -->
            <pe:TypeEditor EditedType="{x:Type Point3DCollection}" EditorTemplate="{StaticResource DatagridEditor}"/>

and in code behind:

        public Point3DCollection MyCollection { get; set; }
        public Window1()

            Point3DCollection p3dc = new Point3DCollection();
            p3dc.Add(new Point3D(0, 0, 0));
            p3dc.Add(new Point3D(1, 1, 1));
            p3dc.Add(new Point3D(2, 2, 2));
            p3dc.Add(new Point3D(1, 2, 3));
            p3dc.Add(new Point3D(3, 2, 1));

            MyCollection = p3dc;
            DataContext = this;

but I got the error (sorry, translate form Italian here): "The access function 'Count' to the object's property Point3D has generated...... The object does not correspond to the destination type".

I have also tried to change the DataTemplate to:

 <DataTemplate x:Key="DatagridEditor">
        <toolkit:DataGrid  AutoGenerateColumns="False" ItemsSource="{Binding Value}">
                <toolkit:DataGridTextColumn Header="X" Width="SizeToCells"
                                            Binding="{Binding X}"
                <toolkit:DataGridTextColumn Header="Y" Width="SizeToCells"
                                            Binding="{Binding Y}"
                <toolkit:DataGridTextColumn Header="Z" Width="SizeToCells"
                                            Binding="{Binding Z}"

 but I got same error.

Is there a way to achieve what I want? If yes, could you give me some info on how?

Many thanks

May 27, 2010 at 7:21 AM

hi stacec, try binding the SelectedObject of the PropertyEditor to an object that contains the collection as a property. Otherwise the properties of the collection will be shown (Count and Items). I will try to create an example using Point3DCollection later, that's a good idea!