PropertyGrid in ItemsControl ItemTemplate is always empty

Open
#1,756 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
desktop

Research direction

No repository files or tests are named. Start by reproducing the supplied WPF ListBox and PropertyGrid XAML with the Company and ViewModel example, then trace the PropertyDefinitions binding inside the DataTemplate. Done means each PropertyGrid receives the collection and displays the Task and HeadNote properties.

Written by the indexing model from the issue text.

Description

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;
    }
}
Dominant language
C#
Stars
4.2k
Forks
912
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from xceedsoftware/wpftoolkit

All issues in xceedsoftware/wpftoolkit

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.