public MeTLTextBoxAutomationPeer(MeTLTextBox owner) : base(owner)
 {
 }
 public static MeTLTextBox toMeTLTextBox(this TextBox OldBox)
 {
     var box = new MeTLTextBox(); 
     box.AcceptsReturn = true;
     box.TextWrapping = TextWrapping.WrapWithOverflow;
     box.BorderThickness = new Thickness(0);
     box.BorderBrush = new SolidColorBrush(Colors.Transparent);
     box.Background = new SolidColorBrush(Colors.Transparent);
     box.tag(OldBox.tag());
     box.FontFamily = OldBox.FontFamily;
     box.FontStyle = OldBox.FontStyle;
     box.FontWeight = OldBox.FontWeight;
     box.TextDecorations = OldBox.TextDecorations;
     box.FontSize = OldBox.FontSize;
     box.Foreground = OldBox.Foreground;
     box.Text = OldBox.Text;
     box.Width = OldBox.Width;
     //box.Height = OldBox.Height;
     InkCanvas.SetLeft(box, InkCanvas.GetLeft(OldBox));
     InkCanvas.SetTop(box, InkCanvas.GetTop(OldBox));
     return box;
 }
 public static MeTLTextBox clone(this MeTLTextBox box)
 {
     if (box == null) return null;
     var newBox = new MeTLTextBox();
     newBox.AcceptsReturn = box.AcceptsReturn;
     newBox.TextWrapping = box.TextWrapping;
     newBox.BorderThickness = box.BorderThickness;
     box.BorderBrush = new SolidColorBrush(Colors.Transparent);
     box.Background = new SolidColorBrush(Colors.Transparent);
     newBox.Text = box.Text;
     newBox.TextAlignment = box.TextAlignment;
     newBox.TextDecorations = box.TextDecorations.Clone();
     newBox.FontFamily = box.FontFamily;
     newBox.FontSize = box.FontSize;
     newBox.FontWeight = box.FontWeight;
     newBox.FontStyle = box.FontStyle;
     newBox.Foreground = box.Foreground;
     newBox.Background = box.Background;
     newBox.tag(box.tag());
     newBox.CaretIndex = box.CaretIndex;
     newBox.Width = Double.IsNaN(box.Width) || box.Width <= 0 ? box.ActualWidth : box.Width;
     newBox.Height = Double.IsNaN(box.Height) || box.Height <= 0 ? box.ActualHeight : box.Height;
     newBox.MaxHeight = box.MaxHeight;
     //newBox.SelectedText = box.SelectedText;
     newBox.SelectionLength = box.SelectionLength;
     newBox.SelectionStart = box.SelectionStart;
     InkCanvas.SetLeft(newBox, InkCanvas.GetLeft(box));
     InkCanvas.SetTop(newBox, InkCanvas.GetTop(box));
     newBox.offsetX = box.offsetX;
     newBox.offsetY = box.offsetY;
     return newBox;
 }
 private MeTLTextBox reassociateTextboxToCanvas(MeTLTextBox text)
 {
     var diffX = logicalX - text.offsetX;
     var diffY = logicalY - text.offsetY;
     if (diffX != 0 || diffY != 0)
     {
         InkCanvas.SetLeft(text, InkCanvas.GetLeft(text) - diffX);
         InkCanvas.SetTop(text, InkCanvas.GetTop(text) - diffY);
         text.offsetX = logicalX;
         text.offsetY = logicalY;
     }
     return text;
 }
 private void doAdjustText(MeTLTextBox box, Func<MeTLTextBox, MeTLTextBox> adjustment)
 {
     adjustment(box);
 }
        public void adjustText(MeTLTextBox box, Func<MeTLTextBox, MeTLTextBox> adjustment)
        {
            reassociateTextboxToCanvas(box);
            var oldCanvasOffsetX = logicalX;
            var oldCanvasOffsetY = logicalY;
            double translateX = 0.0;
            double translateY = 0.0;
            var localX = InkCanvas.GetLeft(box);
            var localY = InkCanvas.GetTop(box);
            if (checkIfLogicalBoundsUpdates(localX, localY))
            {
                var newBounds = generateLogicalBounds(localX, localY);
                logicalX = newBounds.X;
                logicalY = newBounds.Y;
                translateX = ReturnPositiveValue(ReturnPositiveValue(logicalX) - ReturnPositiveValue(oldCanvasOffsetX));
                translateY = ReturnPositiveValue(ReturnPositiveValue(logicalY) - ReturnPositiveValue(oldCanvasOffsetY));

                updateCanvasPositioning(strokeFilter.Strokes, textFilter.TextBoxes.Where(t => ((MeTLTextBox)t).tag().id != box.tag().id), imageFilter.Images,
                                        translateX, translateY);
                reassociateTextboxToCanvas(box);
            }
            doAdjustText(box, adjustment);
        }