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

CustomPropertyItems and Custom Editors

Jan 29, 2015 at 8:45 AM
Hello,

I am trying to have a PropertyGrid with PropertiesSource set to a Collection of CustomPropertyItem's. I cannot get the definition of a custom editor working.

I have a little application to show the problem... The PropertyGrid on the left works as expected, the one on the right doesn't. If I don't specify the EditorDefinitions it has the values. It seems that the {Binding Value} doesn't work with CustomPropertyItems

Please see the litte test-app:

MainWindow.xaml:
<Window x:Class="PropertyGridTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:PropertyGridTest"       
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        Title="MainWindow">

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <xctk:PropertyGrid
                SelectedObject="{Binding TestObject}">

                <xctk:PropertyGrid.EditorDefinitions>
                    <xctk:EditorTemplateDefinition>
                    <xctk:EditorTemplateDefinition.TargetProperties>
                        <xctk:TargetPropertyType Type="{x:Type sys:String}" />
                        <xctk:TargetPropertyType Type="{x:Type sys:Int32}" />
                    </xctk:EditorTemplateDefinition.TargetProperties>

                    <xctk:EditorTemplateDefinition.EditingTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Value}" />
                            </DataTemplate>
                        </xctk:EditorTemplateDefinition.EditingTemplate>
                    </xctk:EditorTemplateDefinition>
                </xctk:PropertyGrid.EditorDefinitions>
            </xctk:PropertyGrid>

            <xctk:PropertyGrid
                Grid.Column="1"
                AutoGenerateProperties="False" 
                            PropertiesSource="{Binding Properties}">

                <xctk:PropertyGrid.EditorDefinitions>
                    <xctk:EditorTemplateDefinition>
                        <xctk:EditorTemplateDefinition.TargetProperties>
                            <xctk:TargetPropertyType Type="{x:Type sys:String}" />
                            <xctk:TargetPropertyType Type="{x:Type sys:Int32}" />
                    </xctk:EditorTemplateDefinition.TargetProperties>
                        <xctk:EditorTemplateDefinition.EditingTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Value}" />
                            </DataTemplate>
                        </xctk:EditorTemplateDefinition.EditingTemplate>
                    </xctk:EditorTemplateDefinition>
                </xctk:PropertyGrid.EditorDefinitions>
            </xctk:PropertyGrid>
        </Grid>
</Window>
And the MainWindow.xaml.cs:
using System.Collections.ObjectModel;
using System.Windows;
using Xceed.Wpf.Toolkit.PropertyGrid;

namespace PropertyGridTest
{
    public partial class MainWindow : Window
    {
        public MyTestObject TestObject { get { return new MyTestObject(); } }
        public ObservableCollection<CustomPropertyItem> Properties { get; set; }

        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            CreateProperties();
        }

        private void CreateProperties()
        {
            Properties = new ObservableCollection<CustomPropertyItem>();
            Properties.Add(new CustomPropertyItem()
            {
                Description = "StringValue-Description",
                DisplayName = "StringValue",
                Value = "String-Value"
            });
            Properties.Add(new CustomPropertyItem()
            {
                Description = "IntValue-Description",
                DisplayName = "IntValue",
                Value = 5
            });
        }
    }

    public class MyTestObject
    {
        public int IntValue { get; set; }
        public string StringValue { get; set; }

        public MyTestObject()
        {
            IntValue = 5;
            StringValue = "Hello!";
        }
    }
}
Thanks for your help!!
Joerg
Developer
Jan 29, 2015 at 6:17 PM
Hi,

Issue https://wpftoolkit.codeplex.com/workitem/21698 has been created.

Looks like you have a Plus version of the Toolkit. If you want faster answers, work-arounds or supports, please use the Xceed e-mail support or forums on Xceed.