How can you hide a sub-property in the Xceed PropertyGrid for WPF?

732 Views Asked by At

We are currently using the Xceed PropertyGrid control to display our application's printing settings. Here is an excerpt from the class we are using:

public class ReportOptions {

    public FontOptions FontOptions { get; } = new FontOptions();
    public PageOptions PageOptions { get; } = new PageOptions();
}

[ExpandableObject]
public class FontOptions {
    public string FontName        { get; set; } = "Times New Roman";
    public double HeadingFontSize { get; set; } = 14.0;
    public double BodyFontSize    { get; set; } = 12.0;
}

[ExpandableObject]
public class PageOptions{

    [ExpandableObject]
    public Thickness Margins { get; set; } = new Thickness(0.5, 1.0, 0.5, 1.0);

    [ExpandableObject]
    public Size      Size    { get; set; } = new Size(8.5,11.0);
}

The issue we are having is the Size class has a read-only IsEmpty property which we would like to hide in the PropertyGrid.

enter image description here

Since we are using the auto-generated properties for the grid, and since we don't 'own' the Size class, we're not sure how to decorate that property to hide it.

We tried using PreparePropertyItem but the PropertyItem.IsVisible is read-only.

So how can we hide that property without having to manually define all properties? (Again, this is just a small excerpt of the actual class.

1

There are 1 best solutions below

0
netniV On

You need the Browsable(false) attribute to hide something from the PropertyGrid. If you need to set the attribute at runtime, you may want to look into something like DynamicTypeDescriptor