Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PropertyGrid in ItemsControl ItemTemplate is always empty #1756

Open
LJN-hzleaper opened this issue Jul 22, 2023 · 1 comment
Open

PropertyGrid in ItemsControl ItemTemplate is always empty #1756

LJN-hzleaper opened this issue Jul 22, 2023 · 1 comment

Comments

@LJN-hzleaper
Copy link

LJN-hzleaper commented Jul 22, 2023

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;
    }
}
@XceedBoucherS
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants