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

本文关键字:ExpandableObject 属性 | 更新日期: 2023-09-27 18:14:12

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

与我试图做的类似的行为的第一个例子是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; }
   }

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

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

using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;

您是否在using语句中包含Xceed.Wpf.Toolkit.PropertyGrid.Attributes名称空间?

相关文章:
  • 没有找到相关文章