private void OnTextBoxKeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Enter: //Confirm the edit EndEdit(true); e.Handled = true; break; case Key.Escape: //Cancel the edit EndEdit(false); e.Handled = true; break; case Key.Tab: AdornedElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); EditableCell nextCell = Keyboard.FocusedElement as EditableCell; if (nextCell != null) { nextCell.IsEditing = true; } e.Handled = true; break; } }
public Editor(EditableCell editableCell) : base(editableCell) { mTextBox = new TextBox(); mTextBox.Padding = new Thickness(0); mTextBox.KeyDown += OnTextBoxKeyDown; mTextBox.LostKeyboardFocus += OnTextBoxLostKeyboardFocus; mVisualChildren = new VisualCollection(this); mVisualChildren.Add(mTextBox); mBinding = mTextBox.SetBinding(TextBox.TextProperty, new Binding() { Path = new PropertyPath(EditableCell.ValueProperty), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.Explicit, Source = editableCell }); BindTextBoxToEditableCell(FrameworkElement.HorizontalAlignmentProperty); BindTextBoxToEditableCell(FrameworkElement.VerticalAlignmentProperty); BindTextBoxToEditableCell(Control.FontFamilyProperty); BindTextBoxToEditableCell(Control.FontSizeProperty); BindTextBoxToEditableCell(Control.FontStretchProperty); BindTextBoxToEditableCell(Control.FontStyleProperty); BindTextBoxToEditableCell(Control.FontWeightProperty); }