Instead of trying to use a command parameter, create a property to store the selected line in:
private Model row; public Model Row { get { return row; } set { if (row != value) { row = value; base.RaisePropertyChanged("Row"); } } }
where Model is the class of objects displayed by your grid. Add the selectedItem property to the datagrid to use the property:
<DataGrid SelectedItem="{Binding Row, UpdateSourceTrigger=PropertyChanged}"/>
then your command goes through the line to the method:
public ICommand DeleteSelectedCommand { get { return new RelayCommand<string>((s) => DeleteRow(Row)); } }
and for your key bindings:
<DataGrid.InputBindings> <KeyBinding Key="Delete" Command="{Binding DeleteSelectedCommand}" /> </DataGrid.InputBindings>
Hope this helps!
source share