How to display collection property on PropertyGrid?

Grids for WPF Forum

Posted 2 years ago by Yuki
Version: 21.1.3
Avatar

Hello,

I want to display collection property on PropertyGrid.

I understand that I should use TypeDescriptorFactory, but I'm not sure how to display collection property.

Would you please tell me how to do it?

<grids:PropertyGrid DataObject="{Binding Properties}" />

DataContext is :

public class MainWindowViewModel
{
  public List<PropertyItem> Properties { get; } = new List<PropertyItem>();

  public MainWindowViewModel()
  {
    Properties.Add(new PropertyItem(){Name = "CustomerName", Value = "AAAA"});
    Properties.Add(new PropertyItem(){Name = "Country", Value = "US"});

    var phoneNumbersProperty = new PropertyItem(){Name = "Phone numbers"};
    phoneNumbersProperty.Children.Add(new PropertyItem(){Name = "Fax", Value = "491-294-1356"});
    phoneNumbersProperty.Children.Add(new PropertyItem(){Name = "Voice", Value = "491-198-1285"});
    Properties.Add(phoneNumbersProperty);
  }

  public class PropertyItem
  {
    // PropertyName
    public string Name { get; set; }

    // PropertyValue
    public object Value { get; set; }

    // Children properties (Expandable items)
    public List<PropertyItem> Children { get; } = new List<PropertyItem>();
  }
}

I want to display it in the same way as lower PropertyGrid of "Custom Data Factory" sample.

Comments (4)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

With the default factory, you would need to set your DataObject to be an object that has the collection property on it.  In your example, if you set the PropertyGrid.DataObject property to an instance of MainWindowViewModel, you should see the Properties collection show up there.


Actipro Software Support

Posted 2 years ago by Yuki
Avatar

I want display as the following when "Properties" is set to PropertyGrid.DataObject .

Is it possible by using custom factory?

--------------------------------------

| Name                 | Value               |

--------------------------------------

   | CustomerName | AAAA               |

--------------------------------------

   | Country              | US                    |

--------------------------------------

v | Phone Numbers |                         |

--------------------------------------

   |   | Fax                  | 491-294-1356  |

--------------------------------------

   |   | Voice              | 491-198-1285  |

--------------------------------------

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Yes, we will update our Custom Data Factory sample to show inclusion of a dictionary.  Please write our support address, mention this thread, and we can send you the updated QuickStart code.


Actipro Software Support

Posted 2 years ago by Yuki
Avatar

Thanks, I will email to support address.

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.