/// <summary> /// Event raised when key is pressed on a datagrid. /// Checks if a cell was deleted. /// If it was deleted then update the database. /// TODO: This should be converted to be done by pure binding instead using this event. /// TODO: USE: xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" for binding! /// TODO: USE: xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" for binding! /// </summary> private void KeywordsDataGrid_PreviewKeyDown(object sender, KeyEventArgs e) { if (Key.Delete == e.Key) { foreach (var row in ((DataGrid)sender).SelectedItems) { if (!row.ToString().Equals("{NewItemPlaceholder}")) { using (var businessContext = new BusinessContext()) { Keyword keyword = (Keyword)row; businessContext.DeleteKeyword(keyword); } } } } }