如何在C#中使用ExpandableObject修饰属性

时间:2013-05-16 18:42:41

标签: c# properties decorator

我试图在每个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; }
   }

2 个答案:

答案 0 :(得分:3)

您应该添加程序集Xceed.Wpf.Toolkit.dll,然后添加以下命名空间:

using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;

答案 1 :(得分:0)

您是否在Xceed.Wpf.Toolkit.PropertyGrid.Attributes声明中包含了using命名空间?