【发布时间】:2013-05-11 19:06:28
【问题描述】:
我正在尝试根据the instructions here 在 Xceed PropertyGrid 中显示此类实例:
PG.SelectedObject = new Order()
{
ShipAddress = "Luisenstr. 48",
ShipCountry = "Germany",
ShipName = "Toms Spezialitaten",
ShipPostalCode = "44087",
chronology = new OrderChronology()
{
OrderDate = new DateTime(1996, 7, 5),
ShippedDate = new DateTime(1996, 8, 16)
}
};
类似于我正在尝试做的行为的 Xceed 示例说 you must decorate your property with the ExpandableObject attribute. 并显示了这一点:
public class Person
{
[Category("Information")]
[DisplayName("First Name")]
[Description("This property uses a TextBox as the default editor.")]
public string FirstName { get; set; }
[Category("Conections")]
[Description("This property is a complex property and has no default editor.")]
[ExpandableObject]
public Person Spouse { get; set; }
}
当我尝试对我的类做同样的事情时(见下文),它会导致编译器错误;它不喜欢[ExpandableObject],并暗示我可能是missing a using directive or assembly reference。我是吗?
public class Order
{
public string ShipAddress { get; set; }
public string ShipCountry { get; set; }
public String ShipName { get; set; }
public String ShipPostalCode { get; set; }
[ExpandableObject]
public OrderChronology chronology;
}
public class OrderChronology
{
public DateTime OrderDate { get; set; }
public DateTime ShippedDate { get; set; }
}
【问题讨论】:
-
就像其他人说的那样,您必须添加对程序集的引用,然后包含 using 语句。我想补充一点,如果您使用的是 Visual Studio,并且您正在使用无法识别的东西,例如您的情况下的 ExpandableObject 属性,您可以按 CTRL+。 (点),它会尝试为您解决它,并为您提供自动包含 using 语句或使用完全限定名称的选项。
-
很遗憾,如果不修改要检查的类型,您就无法做到这一点。
标签: c# properties decorator