I have a DataGrid with ItemsSource bound to <ObservableCollection<MyItem>()
MyItem
is a class with just two public strings. It has a default constructor (sets Text1
to something and Text2
to something (i.e "test1" and "test2").
For the DataGrid, I set CanUserAddRows
to True
and IsReadOnly
is False
.
Yet the DataGrid is not properly adding blank row. I mean it always opens with single blank row at the bottom, but this additional blank row is not set with default values - those I left in MyItem
's default constructor). Also the entire row is kind of like nulled (?). I know that, because I have some XAML bindings to background / foreground cell colors and - on rows (MyItems) I added manually, before I bind the entire ObservableCollection to DataGrid) - those color-bindings work fine. On this odd new blank row, they are failing (saying that they "...can't cast MS.Internal.Namedobject...").
There is one more issue - when I start editing this weird blank row, there is never a new row added automatically at the bottom of DataGrid. Not even after pressing Enter, after in-cell text editing. In WinForms, new blank row always appeared automatically when at least one cell was touched (not even value changed, immediately after click on a blank cell).
What am I missing?