protected override void OnKeyDown(KeyEventArgs e) { bool markHandled = ValueEditorUtils.GetHandlesCommitKeys(this); if (e.Key == Key.Return || e.Key == Key.Enter) { LostFocusAction savedAction = this.lostFocusAction; this.lostFocusAction = LostFocusAction.None; if (savedAction == LostFocusAction.Commit) { this.CommitChange(); } if ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == 0) { this.OnFinishEditing(); } e.Handled |= markHandled; } else if (e.Key == Key.Escape && this.IsEditing) { LostFocusAction savedAction = this.lostFocusAction; this.lostFocusAction = LostFocusAction.None; if (savedAction != LostFocusAction.None) { this.CancelChange(); } this.OnFinishEditing(); e.Handled |= markHandled; } base.OnKeyDown(e); }
protected override void OnLostFocus(RoutedEventArgs e) { base.OnLostFocus(e); this.IsEditing = false; ValueEditorUtils.ExecuteCommand(this.LostFocusCommand, this, null); e.Handled = true; }
private void CancelChange() { ValueEditorUtils.ExecuteCommand(this.BeginCommand, this, null); ValueEditorUtils.UpdateBinding(this, StringEditor.ValueProperty, false); ValueEditorUtils.ExecuteCommand(this.CancelCommand, this, null); ValueEditorUtils.UpdateBinding(this, StringEditor.ValueProperty, UpdateBindingType.Target); this.UpdateTextFromValue(); }
private void CommitChange() { ValueEditorUtils.ExecuteCommand(this.BeginCommand, this, null); this.Value = this.Text; ValueEditorUtils.ExecuteCommand(this.CommitCommand, this, null); ValueEditorUtils.UpdateBinding(this, StringEditor.ValueProperty, UpdateBindingType.Target); // Now update the text value in case the model or a binding has reformated this.UpdateTextFromValue(); }
private void OnFinishEditing() { ICommand finishedEditingCommand = this.FinishEditingCommand; if (finishedEditingCommand != null) { ValueEditorUtils.ExecuteCommand(finishedEditingCommand, this, null); } else { Keyboard.Focus(null); } }
public static void UpdateBinding(FrameworkElement element, DependencyProperty property, bool updateSource) { ValueEditorUtils.UpdateBinding(element, property, (updateSource ? UpdateBindingType.Both : UpdateBindingType.Target)); }