public override TextRun GetTextRun(int textSourceCharacterIndex) { try { foreach (VisualLineElement element in VisualLine.Elements) { if (textSourceCharacterIndex >= element.VisualColumn && textSourceCharacterIndex < element.VisualColumn + element.VisualLength) { int relativeOffset = textSourceCharacterIndex - element.VisualColumn; TextRun run = element.CreateTextRun(textSourceCharacterIndex, this); if (run == null) { throw new ArgumentNullException(element.GetType().Name + ".CreateTextRun"); } if (run.Length == 0) { throw new ArgumentException("The returned TextRun must not have length 0.", element.GetType().Name + ".Length"); } if (relativeOffset + run.Length > element.VisualLength) { throw new ArgumentException("The returned TextRun is too long.", element.GetType().Name + ".CreateTextRun"); } InlineObjectRun inlineRun = run as InlineObjectRun; if (inlineRun != null) { inlineRun.VisualLine = VisualLine; TextView.textLayer.AddInlineObject(inlineRun); } return(run); } } return(new TextEndOfParagraph(1)); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); throw; } }
/// <summary> /// Adds a new inline object. /// </summary> internal void AddInlineObject(InlineObjectRun inlineObject) { inlineObjects.Add(inlineObject); AddVisualChild(inlineObject.Element); inlineObject.Element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); }