Thanks for your reply.
Your workaround gave me an idea that is currently working. It seemed to me that a new "DataGridDetailDescription" is created for each parent row, as opposed to using this object in a static way (no static methods). So, I created my own workaround by changing my implementation of the DataGridDescription class from what I showed in post #19208. I basically included one extra property, and set that property when the GetDetailsForParentItem() method is called.
class ParentDetail : DataGridDetailDescription
{
public ParentDetail()
{
this.RelationName = "ParentDetail";
}
protected override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
{
ParentDataObjectType parentDataObject = parentItem as ParentDataObjectType;
//If no parent object was given, return an empty list of ChildObjects
if (parentDataObject == null)
return new List<ChildObjectType>();
else
{
this.ParentDataObject = parentDataObject;
return parentDataObject.ObservableCollectionChildObjects;
}
}
internal ParentDataObjectType ParentDataObject { get; set; }
}
When the DataGrid's CreatingNewItem event is handled, I check the e.CollectionView.ItemType.Name property to see if this string matches the object name of my child object. Fortunately I'm not using ADO.NET here, or I would be staring at something like "System.Data.DataRow". At that point I cast the event args e.CollectionView.ParentDetailDescription to type ParentDetail with the following code:
ParentDetail parentDetail = e.CollectionView.ParentDetailDescription as ParentDetail;
Now I have access to the parent object via the ParentDataObject property on the parentDetail object!
I can do a similar thing in the InitializingNewItem event, only this time the workaround is a little bit easier. Instead of checking the e.CollectiovView.ItemType.Name property, you can check e.Item directly to see if it is the type that you want to deal with (Parent type, Child type, grandchild type, ect for however many Master/Detail nestings you are doing), and still use the same casting techique to the ParentDetail type.
Hope this helps all other developers consuming the Xceed WPF Grid until the DataGridCreatingNewItemEventArgs and DataGridItemEventArgs are improved to allow direct access to the parent type.
Thanks Jenny, for the inspiration behind this workaround...