How does ListCollectionView.AddNew
determine the type of object it creates, and how could one affect it?
I have a hierarchy of a few types (Base
, DerivedA
, and DerivedB
), and currently my WPF Toolkit DataGrid
creates DerivedA
objects (why, I don't know -- probably because almost all the data in the grid is of that type), but I'd like it to create DerivedB
objects instead.
Update: I've tried deriving a new class from ListCollectionView
and implementing a new AddNew
method for it, and now I'm almost there: the only remaining problem is that after adding a new item, a new new item placeholder isn't added, so I can only add one item. My current approach looks somewhat like this:
public class CustomView : ListCollectionView, IEditableCollectionView
{
public CustomView(System.Collections.IList list)
: base(list)
{
}
object IEditableCollectionView.AddNew()
{
DerivedB obj = new DerivedB();
InternalList.Add(obj);
return obj;
}
}