Gibt es eine hübsche Lösung eines GetPositionAtOffset()
Äquivalents, das nur Texteinfügepositionen statt aller Symbole zählt?GetPositionAtOffset entspricht nur für Text?
Motivation Beispiel in C#:
TextRange GetRange(RichTextBox rtb, int startIndex, int length) {
TextPointer startPointer = rtb.Document.ContentStart.GetPositionAtOffset(startIndex);
TextPointer endPointer = startPointer.GetPositionAtOffset(length);
return new TextRange(startPointer, endPointer);
}
Edit: Bis jetzt habe ich "gelöst" es auf diese Weise
public static TextPointer GetInsertionPositionAtOffset(this TextPointer position, int offset, LogicalDirection direction)
{
if (!position.IsAtInsertionPosition) position = position.GetNextInsertionPosition(direction);
while (offset > 0 && position != null)
{
position = position.GetNextInsertionPosition(direction);
offset--;
if (Environment.NewLine.Length == 2 && position != null && position.IsAtLineStartPosition) offset --;
}
return position;
}
Wow jemand wirklich wollte nicht die RichTextBox verwendet werden .. danke! – gjvdkamp