void textView_VisualLinesChanged(object sender, EventArgs e) { foreach (var ctrl in this.Children) { var currentThumb = ctrl as Thumb; PinDebuggerControl pinControl = TryFindChild <PinDebuggerControl>(currentThumb); if (pinControl != null) { // update relative location Point location = pinControl.Location; location.X += horizontalOffset - textView.HorizontalOffset; location.Y += verticalOffset - textView.VerticalOffset; Canvas.SetLeft(currentThumb, location.X); Canvas.SetTop(currentThumb, location.Y); pinControl.Location = location; pinControl.Mark.PinPosition = new Point { X = location.X + textView.HorizontalOffset, Y = location.Y + textView.VerticalOffset, }; } } verticalOffset = textView.VerticalOffset; horizontalOffset = textView.HorizontalOffset; }
/// <summary> /// Unpins an element. /// </summary> /// <param name="element">Element to unpin.</param> public void Unpin(PinDebuggerControl element) { if (element == null) { throw new NullReferenceException("Element is null!"); } foreach (var thumb in this.Children) { PinDebuggerControl pinControl = TryFindChild <PinDebuggerControl>((DependencyObject)thumb); if (pinControl != null && pinControl == element) { this.Children.Remove((UIElement)thumb); element.Close(); break; } } }
/// <summary> /// Pins an element; /// </summary> /// <param name="element">Element to pin.</param> public void Pin(PinDebuggerControl element) { if (element == null) { throw new NullReferenceException("Element is null!"); } Thumb currentThumb = new Thumb(); // check for saved position if (!element.Mark.PinPosition.HasValue) { // this is satisfied when pinning the first time element.Mark.PinPosition = new Point { X = element.Location.X + textView.HorizontalOffset, Y = element.Location.Y + textView.VerticalOffset }; Canvas.SetTop(currentThumb, element.Location.Y); Canvas.SetLeft(currentThumb, element.Location.X); } else { // this is satisfied when loading the pins - so we might have hidden pins element.Location = new Point { X = element.Mark.PinPosition.Value.X - textView.HorizontalOffset, Y = element.Mark.PinPosition.Value.Y - textView.VerticalOffset }; Canvas.SetTop(currentThumb, element.Mark.PinPosition.Value.Y); Canvas.SetLeft(currentThumb, element.Mark.PinPosition.Value.X); } currentThumb.Style = element.TryFindResource("PinThumbStyle") as Style; currentThumb.ApplyTemplate(); currentThumb.DragDelta += onDragDelta; currentThumb.DragStarted += currentThumb_DragStarted; currentThumb.DragCompleted += currentThumb_DragCompleted; var container = TryFindChild <StackPanel>(currentThumb); container.Children.Add(element); this.Children.Add(currentThumb); }