示例#1
0
 /// <summary>
 /// Called when focus is lost</summary>
 /// <param name="e">Event args</param>
 protected override void OnLostFocus(RoutedEventArgs e)
 {
     base.OnLostFocus(e);
     IsEditing = false;
     ValueEditorUtil.ExecuteCommand(LostFocusCommand, this, null);
     e.Handled = true;
 }
示例#2
0
        /// <summary>
        /// Called when the text changes</summary>
        /// <param name="e">Event args</param>
        protected override void OnTextChanged(TextChangedEventArgs e)
        {
            base.OnTextChanged(e);

            if (!m_ignoreTextChanges)
            {
                ValueEditorUtil.ExecuteCommand(this.TextChangedCommand, this, base.Text);
                if (IsEditing)
                {
                    m_lostFocusAction = LostFocusAction.Commit;
                }
            }
        }
示例#3
0
        private void CommitChange()
        {
            if (!m_transactionOpen)
            {
                ValueEditorUtil.ExecuteCommand(BeginCommand, this, null);
            }

            ValueEditorUtil.UpdateBinding(this, ValueProperty, false);
            ValueEditorUtil.ExecuteCommand(CommitCommand, this, null);
            m_transactionOpen = false;
            ValueEditorUtil.UpdateBinding(this, ValueProperty, UpdateBindingType.Target);

            UpdateTextFromValue();
        }
示例#4
0
        private void OnFinishEditing()
        {
            var finishEditingCommand = FinishEditingCommand;

            if (finishEditingCommand != null)
            {
                ValueEditorUtil.ExecuteCommand(finishEditingCommand, this, null);
            }
            else
            {
                //Keyboard.Focus(null);
                MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            }
        }
示例#5
0
        private void UpdateChange()
        {
            if (!m_transactionOpen)
            {
                ValueEditorUtil.ExecuteCommand(BeginCommand, this, null);
            }

            Value = UnFormat(Text);

            ValueEditorUtil.ExecuteCommand(UpdateCommand, this, null);
            m_transactionOpen = true;
            ValueEditorUtil.UpdateBinding(this, ValueProperty, UpdateBindingType.Target);

            UpdateTextFromValue();
        }
示例#6
0
        /// <summary>
        /// Called when a key is pressed</summary>
        /// <param name="e">Event args</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            bool handlesCommitKeys = ValueEditorUtil.GetHandlesCommitKeys(this);

            if (e.Key == Key.Return)
            {
                var lostFocusAction = m_lostFocusAction;
                m_lostFocusAction = LostFocusAction.None;

                bool shiftNone = (e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.None;
                if (lostFocusAction == LostFocusAction.Commit)
                {
                    if (shiftNone)
                    {
                        CommitChange();
                    }
                    else
                    {
                        UpdateChange();
                    }
                }

                if (shiftNone)
                {
                    OnFinishEditing();
                }

                e.Handled |= handlesCommitKeys;
            }
            else if ((e.Key == Key.Escape) && IsEditing)
            {
                var lostFocusAction = m_lostFocusAction;
                m_lostFocusAction = LostFocusAction.None;
                if (lostFocusAction != LostFocusAction.None)
                {
                    CancelChange();
                }

                OnFinishEditing();
                e.Handled |= handlesCommitKeys;
            }

            base.OnKeyDown(e);
        }