internal override void OnInput(InputEventArgs e) { // Text input will start an edit. // Escape is meant to be for CancelEdit. But DataGrid // may not handle KeyDown event for Escape if nothing // is cancelable. Such KeyDown if unhandled by others // will ultimately get promoted to TextInput and be handled // here. But BeginEdit on escape could be confusing to the user. // Hence escape key is special case and BeginEdit is performed if // there is atleast one non espace key character. if (DataGridHelper.HasNonEscapeCharacters(e as TextCompositionEventArgs)) { BeginEdit(e, true); } else if (DataGridHelper.IsImeProcessed(e as KeyEventArgs)) { if (DataGridOwner != null) { DataGridCell cell = DataGridOwner.CurrentCellContainer; if (cell != null && !cell.IsEditing) { Debug.Assert(e.RoutedEvent == Keyboard.PreviewKeyDownEvent, "We should only reach here on the PreviewKeyDown event because the TextBox within is expected to handle the preview event and hence trump the successive KeyDown event."); BeginEdit(e, false); // // The TextEditor for the TextBox establishes contact with the IME // engine lazily at background priority. However in this case we // want to IME engine to know about the TextBox in earnest before // PostProcessing this input event. Only then will the IME key be // recorded in the TextBox. Hence the call to synchronously drain // the Dispatcher queue. // Dispatcher.Invoke((Action) delegate(){}, System.Windows.Threading.DispatcherPriority.Background); } } } }