Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: CustomPropertyItems and Custom Editors

$
0
0
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

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>