How to decorate property with ExpandableObject in C#

a 夏天 提交于 2019-12-24 12:17:06

问题


I am trying to display this class instance in the Xceed PropertyGrid per the instructions here:

    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)
            }

        };

The Xceed example for behavior analogous to what I am trying to do says you must decorate your property with the ExpandableObject attribute. and shows this:

       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; }
    }

When I try to do the same with my class (see below) it causes a compiler error; it does not like [ExpandableObject] and hints that I may be missing a using directive or assembly reference. Am I?

 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; }
   }

回答1:


You should add assembly Xceed.Wpf.Toolkit.dll and after that you should add following namespace:

using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;



回答2:


Are you including the Xceed.Wpf.Toolkit.PropertyGrid.Attributes namespace in your using statements?



来源:https://stackoverflow.com/questions/16595055/how-to-decorate-property-with-expandableobject-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!