【问题标题】:How to decorate property with ExpandableObject in C#如何在 C# 中使用 ExpandableObject 装饰属性
【发布时间】: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


【解决方案1】:

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

using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2019-06-21
      • 1970-01-01
      • 1970-01-01
      • 2019-08-19
      • 1970-01-01
      • 2021-12-15
      • 2019-11-02
      • 2012-02-16
      相关资源
      最近更新 更多