コード例 #1
0
        /// <summary>
        /// Shows the <see cref="TextBox"/>.
        /// </summary>
        private void ShowTextBox()
        {
            _cancelEditing = false;

            _textBoxAdorner           = new TextBoxAdorner(_textBlock);
            _textBoxAdorner.MaxWidth  = MaxWidth;
            _textBoxAdorner.MaxHeight = MaxHeight;

            _textBoxAdorner.TextBox.Text = Text;
            _textBoxAdorner.TextBox.SelectAll();

            // Bind style of text box to TextBoxStyle
            Binding binding = new Binding("TextBoxStyle")
            {
                Source = this
            };

            _textBoxAdorner.TextBox.SetBinding(StyleProperty, binding);

            _textBoxAdorner.TextBox.KeyDown           += OnTextBoxKeyDown;
            _textBoxAdorner.TextBox.LostKeyboardFocus += OnTextBoxLostKeyboardFocus;

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(_textBlock);

            adornerLayer.Add(_textBoxAdorner);
        }
コード例 #2
0
        /// <summary>
        /// Removes the <see cref="TextBox"/>.
        /// </summary>
        private void RemoveTextBox()
        {
            if (_textBoxAdorner != null)
            {
                if (!_cancelEditing)
                {
                    // Accept input
                    Text = _textBoxAdorner.TextBox.Text;
                }

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(_textBlock);
                adornerLayer.Remove(_textBoxAdorner);
                _textBoxAdorner = null;
            }
        }
コード例 #3
0
        /// <summary>
        /// Shows the <see cref="TextBox"/>.
        /// </summary>
        private void ShowTextBox()
        {
            _cancelEditing = false;

            _textBoxAdorner = new TextBoxAdorner(_textBlock);
            _textBoxAdorner.MaxWidth = MaxWidth;
            _textBoxAdorner.MaxHeight = MaxHeight;

            _textBoxAdorner.TextBox.Text = Text;
            _textBoxAdorner.TextBox.SelectAll();

            // Bind style of text box to TextBoxStyle
            Binding binding = new Binding("TextBoxStyle") { Source = this };
            _textBoxAdorner.TextBox.SetBinding(StyleProperty, binding);

            _textBoxAdorner.TextBox.KeyDown += OnTextBoxKeyDown;
            _textBoxAdorner.TextBox.LostKeyboardFocus += OnTextBoxLostKeyboardFocus;

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(_textBlock);
            adornerLayer.Add(_textBoxAdorner);
        }
コード例 #4
0
        /// <summary>
        /// Removes the <see cref="TextBox"/>.
        /// </summary>
        private void RemoveTextBox()
        {
            if (_textBoxAdorner != null)
            {
                if (!_cancelEditing)
                {
                    // Accept input
                    Text = _textBoxAdorner.TextBox.Text;
                }

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(_textBlock);
                adornerLayer.Remove(_textBoxAdorner);
                _textBoxAdorner = null;
            }
        }