Skip to content

PropertyGrid in ItemsControl ItemTemplate is always empty #1756

@LJN-hzleaper

Description

@LJN-hzleaper

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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions