xceedsoftware/wpftoolkit

PropertyGrid - Collections in sub items are not firing events or receiving templates

midspace opened this issue · 4 comments

The PropertyGrid is not applying Editor Definitions or receiving PropertyValueChanged event notifications from certain parts of a complex model.
Tested with version 4.1

This is a basic pseudocode of the model.
Properties in Model5 do not trigger the PropertyValueChanged event, and do not apply the EditorTemplateDeninifion.

Model1
{
string Property1
int Property2
Model2 Property3
Model3 Collection Property4
}

Model2
{
string Property1
int Property2
Model5 Collection Property3
}

Model3
{
string Property1
int Property2
Model4 Collection Property3
}

Model4
{
string Property1
int Property2
}

Model5
{
string Property1
int Property2
}

image

Find attached a working sample of the code.
WpfApp1-xceed propertygrid bugs.zip

Hi,

Thank you for the sample. If I run it with Toolkit v4.1, and click on "Items" dropdown, I can see the CollectionControl.
Then, If I click the "Add" button, I can see a new MainItem in the PropertyGrid of the CollectionControl with a Green border for the "Name" property.
image

What exactly is the problem ?
Thank you

As explained, the issue is with the collection in the sub item

  1. Run the sample.
  2. Expand the Sub Item.
  3. Click on the Items Collection in the Sub Item
    image
  4. In the collection control that appears, click the Add Button.
  5. The PropertyGrid appears, but the Name property does not have the Green border denoting that it has a Templated control.

This sample has the PropertyValueChanged event notification connected and displayed at the bottom of the main window.
If you make a change in any of the properties, it should display "true"
Clicking on the "clear changes" button will change it back to "false"
It the collection under the Sub Item, none of the changes in it will trigger the PropertyValueChanged event.

Hi,
Thank you for the explanations and screenshots.
The issue has been identified and will be fixed in v4.3.

In the meantime, you can go in file Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/CollectionEditors.cs,

  1. In method SetControlProperties() and Editor_CollectionUpdated()
    Replace the lines:
    var propertyGrid = propertyItem.ParentElement as PropertyGrid;
    by;
    var propertyGrid = this.GetParentPropertyGrid( propertyItem.ParentElement );

  2. Add the following method:
    private PropertyGrid GetParentPropertyGrid( FrameworkElement element )
    {
    var propertyGrid = element as PropertyGrid;
    if( propertyGrid == null )
    {
    var parentPropertyItem = element as PropertyItem;
    while( ( parentPropertyItem != null ) && ( propertyGrid == null ) )
    {
    propertyGrid = parentPropertyItem.ParentElement as PropertyGrid;
    if( propertyGrid == null )
    {
    parentPropertyItem = parentPropertyItem.ParentElement as PropertyItem;
    }
    }
    }

    return propertyGrid;
    }

This will search the ancestor of type PropertyGrid to fix the issue for sub-Properties.
This will all be part of v4.3.
Thank you