views:

124

answers:

1

We were having some issues with the wpf datagrid and IEditableCollectionView (although this question applies to using IEditableCollectionView and ItemsControl) When you have a collection with no items in it, the IEditableCollectionView cannot determine what items should be inserted so it sets CanAddNew=false we found a solution here (buried deep in the comments) that goes like so :

If you derive from ObservableCollection like this

public class PersonsList : ObservableCollection<Person> { }

you will find out that if the initial collection is empty, there won't be a NewItemPlaceHolder showing up on the view. That's because PersonsList cannot resolve type T at design time. A workaround that works for me is to pass type T as a parameter into the class like this

PersonsList<T> : ObservableCollection<T> where T : Person { }

This approach will place the NewItemPlaceHolder even if the collection is empty.

I'm wondering if there is an interface i can implement on my collections that inform the IEditableCollectionView which type to create should i get an AddNew request.

A: 

Try implementing IEditableObject on T and see if the problem goes away. Vincent Sibal says this is necessary. But he also claims PersonsList<T> is also needed, but you figured this out already. Hopefully, IEditableObject is enough and you'd be able to use non-generic class.

wpfwannabe