Example #1
0
        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);
        }
Example #2
0
 protected override void OnLostFocus(RoutedEventArgs e)
 {
     base.OnLostFocus(e);
     this.IsEditing = false;
     ValueEditorUtils.ExecuteCommand(this.LostFocusCommand, this, null);
     e.Handled = true;
 }
Example #3
0
 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();
 }
Example #4
0
 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();
 }
Example #5
0
        private void OnFinishEditing()
        {
            ICommand finishedEditingCommand = this.FinishEditingCommand;

            if (finishedEditingCommand != null)
            {
                ValueEditorUtils.ExecuteCommand(finishedEditingCommand, this, null);
            }
            else
            {
                Keyboard.Focus(null);
            }
        }
Example #6
0
 public static void UpdateBinding(FrameworkElement element, DependencyProperty property, bool updateSource)
 {
     ValueEditorUtils.UpdateBinding(element, property, (updateSource ? UpdateBindingType.Both : UpdateBindingType.Target));
 }