问题
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