I have a table that stores data received from an external Internet resource. When changing a table cell, I need to send new data to the server. The question is how to correctly bind the property that will store the new data?
The View DataGrid XAML:
<DataGrid Grid.Row="2"
ItemsSource="{Binding Properties, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
AutoGenerateColumns="False"
IsReadOnly="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=name}"
IsReadOnly="False"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Value">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=value}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
And View Model Property of collection that places in DataGrid:
private ObservableCollection<IProperties> _Properties;
public ObservableCollection<IProperties> Properties
{
get => _Properties;
set
{
_Properties = value;
OnPropertyChanged(nameof(Properties));
}
}