I have ObservableCollection<IInterface> which is binded to DataGrid.
IInterface is interface.
I want to add new row clearly for user (without add button). I’ve added CanUserAddRows="true" but it works only when dataGrid is binded on ObservableCollection<MyClass>.
How can I programmatically create new object for new row?
I’ve recently had the same issue. I’ve posted a solution in my blog: Enable inline adding of records for view models with non-default constructors/interfaces
It basically involves creating a custom ListCollectionView (can be done similarly for the others) and binding the grid to that view. The custom view has a factory method used to create the rows as the default implementation in ListCollectionView doesn’t support adding rows for interfaces or classes which do not have a default constructor.
Note that even if you do not use a CollectionView in your MVVM view model, but a regular list or an IBindingList, WPF will create a specific collection view for you. See more details WPF’s CollectionViewSource