Esempio n. 1
0
        public EditableTextBlockAdorner(EditableTextBlock adornedElement)
            : base(adornedElement)
        {
            myTextBlock = adornedElement;

            myTextBox = CreateTextBox(adornedElement);

            myCollection = new VisualCollection(this);
            myCollection.Add(myTextBox);
        }
Esempio n. 2
0
        private TextBox CreateTextBox(EditableTextBlock adornedElement)
        {
            var textBox = new TextBox();

            Binding binding = new Binding("Text")
            {
                Source = adornedElement,
                UpdateSourceTrigger = UpdateSourceTrigger.Explicit
            };

            textBox.SetBinding(TextBox.TextProperty, binding);

            textBox.AcceptsReturn = true;
            textBox.MaxLength     = adornedElement.MaxLength;
            textBox.KeyUp        += myTextBox_KeyUp;
            textBox.LostFocus    += myTextBox_LostFocus;
            textBox.SelectAll();

            return(textBox);
        }
Esempio n. 3
0
        /// <summary>
        /// Determines whether [is in edit mode update] [the specified obj].
        /// </summary>
        private static void IsInEditModeUpdate(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            EditableTextBlock textBlock = obj as EditableTextBlock;

            if (textBlock == null)
            {
                return;
            }

            //Get the adorner layer of the uielement (here TextBlock)
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(textBlock);

            //If the IsInEditMode set to true means the user has enabled the edit mode then
            //add the adorner to the adorner layer of the TextBlock.
            if (textBlock.IsInEditMode)
            {
                if (null == textBlock.myAdorner)
                {
                    textBlock.myAdorner = new EditableTextBlockAdorner(textBlock);
                }
                layer.Add(textBlock.myAdorner);
            }
            else
            {
                //Remove the adorner from the adorner layer.
                Adorner[] adorners = layer.GetAdorners(textBlock);
                if (adorners != null)
                {
                    foreach (Adorner adorner in adorners)
                    {
                        if (adorner is EditableTextBlockAdorner)
                        {
                            layer.Remove(adorner);
                        }
                    }
                }
            }
        }