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

New Post: Setting TargetProperties on a PropertyGrid EditorTemplateDefinition

$
0
0
Hello,

I have the following C# code:
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            And andGate = new And("And");
            andGate.Values = new ValuesClass();
            andGate.Values.MyList.Add("one");
            andGate.Values.MyList.Add("two");
            andGate.Values.SelectedValue = "two";
           
            PropertyGrid.SelectedObject = andGate;


        }
    }

    public class And
    {
        [CategoryAttribute("Properties"),
        DisplayName("Values"),
        DescriptionAttribute("Value of the node")]
        public ValuesClass Values { get; set; }

        public string Name { get; set; }

        public And(string name)
        {
            this.Name = name;
        }
    }
    public class ValuesClass
    {
        public string SelectedValue { get; set; }
        public ObservableCollection<string> MyList { get; set; }

        public ValuesClass() 
        {
            MyList = new ObservableCollection<string>();
        }
    }
I have the following XAML to show the "MyList" property in the properties window as an Editable ComboBox, and I keep the "Name" property as the default TextBox.
<xctk:PropertyGrid x:Name="PropertyGrid" Width="450"  Margin="10">
            <xctk:PropertyGrid.EditorDefinitions>
                <xctk:EditorTemplateDefinition TargetProperties="{x:Type local:ValuesClass}">
                    <xctk:EditorTemplateDefinition.EditingTemplate>
                        <DataTemplate>
                            <ComboBox SelectedItem="{Binding Value.SelectedValue}" ItemsSource="{Binding Value.MyList}" IsEditable="True"/>
                        </DataTemplate>
                    </xctk:EditorTemplateDefinition.EditingTemplate>
                </xctk:EditorTemplateDefinition>
            </xctk:PropertyGrid.EditorDefinitions>
        </xctk:PropertyGrid>
This actually seems to work fine when it is run (everything works as expected), but I get the following XAML compile error when I set the TargetProperties:
"The specified value cannot be assigned. The following type was expected: "IList"."

This is causing me some grief because this markup error is preventing me from seeing the form in the design view in Visual Studio. I have also tried to set the TargetProperties this way:
<xctk:EditorTemplateDefinition.TargetProperties>
                        <xctk:TargetPropertyType Type="{x:Type local:ValuesClass}"/>
                    </xctk:EditorTemplateDefinition.TargetProperties>
Which also works, but it gives me a different XAML error saying that the collection is read-only and also doesn't allow me to view the form in the design view.

I am a using trial version 2.1 plus of the toolkit.

Viewing all articles
Browse latest Browse all 4964

Trending Articles



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