简体   繁体   English

如何在Xceed PropertyGrid for WPF中隐藏子属性?

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

We are currently using the Xceed PropertyGrid control to display our application's printing settings. 当前,我们正在使用Xceed PropertyGrid控件来显示应用程序的打印设置。 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 . 我们遇到的问题是Size类具有一个只读的IsEmpty属性,我们希望将其隐藏在PropertyGrid

在此处输入图片说明

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. 由于我们将自动生成的属性用于网格,并且由于我们不“拥有” Size类,因此我们不确定如何装饰该属性以将其隐藏。

We tried using PreparePropertyItem but the PropertyItem.IsVisible is read-only. 我们尝试使用PreparePropertyItemPropertyItem.IsVisible为只读。

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. (同样,这只是实际课程的一小部分摘录。

You need the Browsable(false) attribute to hide something from the PropertyGrid. 您需要Browsable(false)属性才能从PropertyGrid中隐藏某些内容。 If you need to set the attribute at runtime, you may want to look into something like DynamicTypeDescriptor 如果需要在运行时设置属性,则可能需要查看类似DynamicTypeDescriptor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM