This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product. Otherwise - post away!
Good morning, I am looking for a way to bind an Entity Framework entity to the Property Grid, and eventually to be able to Add & Delete entities from the many side of the relationship.
For the moment I am concentrating on the first part, for the pourposes of simplicity we can imagine my model to look like this :
Customer & CustomerOrder and a realationship where each customer can have one or many orders.
What I want is to bind the Property Grid to a Customer and for the PG to show a list of Orders, currently what I am seeing is the Customer and the EntityCollection<CustomerOrders> but it doesnt appear to list individual CustomerOrders only various attributes of the EntityCollection.
Can you offer any guidance
The WPF Property Grid collections support requires that the child items be properties of the collection object -- i.e. we require an indexer property for the collection elements, i.e. an IList or IDictionary. EntityCollection implements only ICollection<T>: its elements are not (indexed) properties, so the property grid can't get at them. We therefore fall back on treating it as an "ordinary" child object rather than an expandable collection.
The only way around this is to make the Orders property non-browsable, and create a wrapper property of type ObservableCollection<CustomerOrder> which was initialised to the contents of the EntityCollection and reflected adds and deletes down to the underlying EntityCollection.
Alternatively, instead of relying on the built-in add/delete UI, you could create a custom TypeEditor for the EntityCollection<T> type which displayed your own custom UI, e.g. in a dialog.