private void RemoveRowButton_Click(object sender, RoutedEventArgs e) { int index = (MainGrid.SelectedIndex - 1).Clamp(0, _model.VaultCollection.Count); EntryModel item = (EntryModel)MainGrid.SelectedItem; if (item == null) { return; } _model.VaultCollection.Remove(item); _dataChanged = true; if (MainGrid.GetRecordsCount() > 0) { MainGrid.SelectedItem = _model.VaultCollection[index]; } }