I'm unable to add new rows in my DataGrid
from UI. Below is my code.
<DataGrid CanUserAddRows="True" Name="dg" ItemsSource="{Binding list}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=.}" Header="Text"/>
<DataGridTextColumn Binding="{Binding Length}" Header="Length"/>
</DataGrid.Columns>
</DataGrid>
list
is a list of string in aboveBinding
.Usually when I setCanUserAddRows="True"
I was able to add rows on UI automatically in other examples.
My property is as following:
public List<string> list { get; set; }
And before display of DataGrid
it has been initialized. So no need to implement INotifyPropertyChanged
for this property.
Can someone explain me why the DataGrid
is behaving this way? How to achieve desired behavior?