I have a DataGrid with the following properties:
<DataGrid x:Name="dg_words" ItemsSource="{Binding}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Id" Binding="{Binding id}" />
<DataGridTextColumn Header="word" Binding="{Binding word}" IsReadOnly="False"/>
</DataGrid.Columns>
</DataGrid>
This DataGrid has two columns. First is a read-only column (Id) and second is editable (word).
I used a list to fill this DataGrid.
List<Tuple<int, string>> l = new List<Tuple<int, string>>();
l.Add(new Tuple<int, string>(1, "word 1"));
l.Add(new Tuple<int, string>(2, "word 2"));
l.Add(new Tuple<int, string>(3, "word 3"));
var l1 = (from p in l
select new { Id = p.Item1, word = p.Item2 }).ToList();
dg_quran_words.ItemsSource = l1;
When I try to edit a cell in column word, throw an exception as:
Additional information: A TwoWay or OneWayToSource binding cannot work on the read-only property 'word' of type ...
get
andset
accessors instead of anonymous one – Pavel Anikhouski