This project has moved. For the latest updates, please go here.

PropertyGrid does not work to expand the use expandable object

Oct 5, 2015 at 4:02 PM
Expandable object does not work when using the ExpandableObjectConverter and PropertyDescriptor, I use to generate dynamic Properties to not have to create a class for each type of editing, I was looking at the code from version 2.5.0.0 source code and found qu is by because of a binding that takes place, but as the Properties are dynamic binding is not performed.

To test I changed this block of code:
    protected override BindingBase CreateValueBinding()
    {
      //Bind the value property with the source object.
      var binding = new Binding( PropertyDescriptor.Name )
      {
        Source = SelectedObject,
        Mode = PropertyDescriptor.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay,
        ValidatesOnDataErrors = true,
        ValidatesOnExceptions = true
      };

      return binding;
    }
For this:
    protected override BindingBase CreateValueBinding()
    {
      //Bind the value property with the source object.

        Value = PropertyDescriptor.GetValue(SelectedObject);

      return null;
    }
and, this:
    public virtual void InitProperties()
    {
      // Do "IsReadOnly" and PropertyName first since the others may need that value.
      _isReadOnly = ComputeIsReadOnly();
      _category = ComputeCategory();
      _categoryValue = ComputeCategoryValue();
      _description = ComputeDescription();
      _displayName = ComputeDisplayName();
      _displayOrder = ComputeDisplayOrder( this.IsPropertyGridCategorized );
      _expandableAttribute = ComputeExpandableAttribute();
      _newItemTypes = ComputeNewItemTypes();
      _commandBindings = new CommandBinding[] { new CommandBinding( PropertyItemCommands.ResetValue, ExecuteResetValueCommand, CanExecuteResetValueCommand ) };

      UpdateIsExpandable();
      UpdateAdvanceOptions();

      BindingBase valueBinding = this.CreateValueBinding();
      BindingOperations.SetBinding( this, DescriptorPropertyDefinitionBase.ValueProperty, valueBinding );
    }
For this:
    public virtual void InitProperties()
    {
      // Do "IsReadOnly" and PropertyName first since the others may need that value.
      _isReadOnly = ComputeIsReadOnly();
      _category = ComputeCategory();
      _categoryValue = ComputeCategoryValue();
      _description = ComputeDescription();
      _displayName = ComputeDisplayName();
      _displayOrder = ComputeDisplayOrder( this.IsPropertyGridCategorized );
      _expandableAttribute = ComputeExpandableAttribute();
      _newItemTypes = ComputeNewItemTypes();
      _commandBindings = new CommandBinding[] { new CommandBinding( PropertyItemCommands.ResetValue, ExecuteResetValueCommand, CanExecuteResetValueCommand ) };

      UpdateIsExpandable();
      UpdateAdvanceOptions();

      CreateValueBinding();
    }
I changed only for testing, it is not the solution, if you sample code to understand or have no choice, I'm available.
Developer
Oct 6, 2015 at 7:45 PM
Hi,

The "CreateValueBinding()" method will be modified in v2.9.
Can you submit a sample of your bug so we could test if the new "CreateValueBinding()" fixes the issue.

Thanks.
Oct 7, 2015 at 2:14 AM
Below the link to download the source code, this referencing the Xceed.Wpf.Toolkit that changed in this case will work, but if the original reference is not possible to expand the propiedade within the object.

source code test
Oct 8, 2015 at 12:55 PM
Hi, I was wondering if this issue will be arranged in the next version or will not be changed.

Thanks.
Developer
Oct 16, 2015 at 6:31 PM
Hi,

Instead of modifying the existing code for the Value binding, I've you thought about using the PropertyGrid.Properties property instead of PropertyGrid.SelectedObject property ? You could define your own CustomPropertyItems.
Since you don't seem to need the binding, this could be an option :
 <xctk:PropertyGrid x:Name="_propertyGrid" Width="450" MaxHeight="375" Margin="10">
         <xctk:PropertyGrid.CategoryGroupDescription>
            <PropertyGroupDescription PropertyName="Category"/>
         </xctk:PropertyGrid.CategoryGroupDescription>
</xctk:PropertyGrid>
var obj2 = new CustomPropertyItem
      {
        Description = "Propiedades da lista de usúarios",
        DisplayName = "UsersList",
        IsExpandable = true,
        Category = "Componentes",
        Value = "Componente 1",
        Properties =
                {
                    new CustomPropertyItem
                    {
                        Description = "Id da configuração de pesquisa de úsuario",
                        Category = "Propiedades",
                        DisplayName = "UserSearchId",
                        Value = 0
                    },
                    new CustomPropertyItem
                    {
                        Description = "Id da tabela de visualização de úsuarios",
                        Category = "Propiedades",
                        DisplayName = "UserTableId",
                        Value = 0
                    },
                },
      };

  _propertyGrid.Properties.Add( obj2 );
Please note that the subItems may not have the Category added. We are aware of this and try to do a fix for it.