xceedsoftware/wpftoolkit

PropertyGrid in ItemsControl ItemTemplate is always empty

Opened this issue · 1 comments

I bind PropertyGrid(in ListBox ItemTemplate) PropertyDefinitions to a PropertyDefinitionCollection in my viewmodel, but I find the binding does not work, the PropertyDefinitionCollection of all PropertyGrid is empty, and all PropertyGrid are empty. Here is my code:

<ListBox ItemsSource="{Binding  ManufacturerList}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <xctk:PropertyGrid
                SelectedObject="{Binding }"
                AutoGenerateProperties="False"
                PropertyDefinitions="{Binding DataContext.PropertyDefinitionCollection, ElementName=window}">
            </xctk:PropertyGrid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
public class Company
{
    public string Task { get; set; }
    public string HeadNote { get; set; }
}
public class ViewModel
{
    public PropertyDefinitionCollection PropertyDefinitionCollection { get; set; } =
        new PropertyDefinitionCollection()
        {
            new PropertyDefinition()
            {
                TargetProperties = new[] { "Task" }
            },
            new PropertyDefinition()
            {
                TargetProperties = new[] { "HeadNote" }
            }
        };

    public List<Company> ManufacturerList { get; set; }

    public ViewModel()
    {
        List<Company> list = new List<Company>();

        list.Add(new Company()
        {
            Task = "Coding",
            HeadNote = "Coding Task",
                
        });


        list.Add(new Company()
        {
            Task = "Communicate",
            HeadNote = "Communicate Task",
        });

        ManufacturerList = list;
    }
}

Hi,

This issue has been fixed. The fix will be part of v4.7.

In the meantime, you can go in file Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGrid.cs, in the constructor, and replace:
PropertyDefinitions = new PropertyDefinitionCollection();
with:
this.SetCurrentValue( PropertyGrid.PropertyDefinitionsProperty, new PropertyDefinitionCollection() );

Thank you