public Point GetPositionFromCharIndex(int charIndex) { var offset = new TextRange(ContentStart, textBox.CaretPosition) .Start .GetPositionAtOffset(charIndex, LogicalDirection.Forward); return(offset != null ? offset.GetCharacterRect(LogicalDirection.Forward).BottomLeft : new Point(0, 0)); }
private void MoveCaretToDirection(LogicalDirection pDirection) { var lTextPointer = new TextRange(NumericDisplay.ContentStart, NumericDisplay.ContentEnd).End; var lRect = lTextPointer.GetCharacterRect(pDirection); var lCaretLocationX = lRect.X; var lCaretLocationY = lRect.Y; if (!double.IsInfinity(lCaretLocationX)) Canvas.SetLeft(Caret, lCaretLocationX); if (!double.IsInfinity(lCaretLocationY)) Canvas.SetTop(Caret, lCaretLocationY); }