I'm developing an Avalonia Application and I'm trying to figure out how can I make a DataGrid cell editable, here's my DataGrid to make it more clear:
<DataGrid IsReadOnly="False" CanUserResizeColumns="False" ItemsSource="{Binding Employees}" Margin="10" CornerRadius="10">
<DataGrid.Columns>
<DataGridTextColumn Header="DIPENDENTE" Binding="{Binding dipendente}"/>
<DataGridTemplateColumn Header="ATTIVO">
<DataTemplate>
<CheckBox IsChecked="{Binding attivo}"
Command="{Binding $parent[DataGrid].((vm:AggiungiDipendenteViewModel)DataContext).ChangeStatusCommand}"
CommandParameter="{Binding .}"/>
</DataTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="MAIL" Binding="{Binding mail}"/>
<DataGridTextColumn Header="ASSUNZIONE" Binding="{Binding assunzione, StringFormat='{}{0:dd-MM-yyyy}'}"/>
<DataGridTextColumn Header="RUOLO" Binding="{Binding tipo}"/>
<DataGridTextColumn Header="SESSO" Binding="{Binding sex}"/>
</DataGrid.Columns>
</DataGrid>
As I did for the ComboBox, that I made it clickable and behind it executes a query on db that changes the status from false to true and viceversa, Now I have to do the same thing for all the cells, I mean, every value of this DataGrid can be editable but after the edit(when the user press Enter), I have to put it on DB through a query, so in my ViewModel the public property takes the new value and it will show it up in the UI, then it will go as a parameter on a DB query but I don't know how to intercept the enter key when the user finishes to edit the cell. For example the user wants to edit the employee cell that contains name and surname because when he first added the employee he made a typo, so he will click on the cell and change the name, as he press enter (or he exits from editing the cell) I want it to go on a function that takes the new value of the cell and passes that value on an UPDATE query.
P.S. Of course the ItemSource of the DataGrid it's in the ViewModel and it is an ObservableCollection that inherits from a class.
I apologize if I repeated too many things, but I hope I explained everything clearly so that you can understand the real issue I'm facing.