/// <summary> /// /// </summary> /// <param name="bm"></param> /// <param name="bookmarkOffset"></param> /// <returns>The updated bookmark, null if the hyperlink no longer exists in the document</returns> private Bookmark CalculateBookMarkInfo(Bookmark bm, double?bookmarkOffset = null) { if (!bookmarkOffset.HasValue) { var rect = bm.Hyperlink.ContentStart.GetCharacterRect(LogicalDirection.Forward); if (rect.IsEmpty) { return(null); } bookmarkOffset = rect.Top; } TextPointer pos = MainTextBox.GetPositionFromPoint(new Point(0, bookmarkOffset.GetValueOrDefault()), true); TextPointer endPos = MainTextBox.GetPositionFromPoint(new Point(MainTextBox.ActualWidth, bookmarkOffset.GetValueOrDefault()), true); if (pos == null) { Trace.Fail("Could not get text start position for bookmark"); return(null); } if (endPos == null) { Trace.Fail("Could not get text end position for bookmark"); return(null); } int num = DocumentHelpers.GetLineNumberFromPosition(_mainTextBox, pos); if (bm.Hyperlink == null) { var hyperlink = new Hyperlink(pos, pos); bm.Hyperlink = hyperlink; if (BookmarkImage != null) { var img = new Image(); img.Source = BookmarkImage; img.Visibility = Visibility.Collapsed; bm.Image = img; hyperlink.Inlines.Add(" "); } } var textRange = new TextRange(pos, endPos); string toolTipText = textRange.Text; bm.Line = num; bm.TopOffset = bookmarkOffset.GetValueOrDefault(); if (string.IsNullOrWhiteSpace(toolTipText)) { toolTipText = "<<Blank line>>"; } bm.TooltipText = string.Format("{0} (Line: {1})", toolTipText, num); bm.Name = bm.TooltipText; bm.Hyperlink.NavigateUri = new Uri(String.Format("http://bookmark/{0}", bm.Name)); bm.Position = pos; return(bm); }