FlowDocument GetCharRect returning infinity for top, bottom, left right - How get rectangle for offset position from document

joe blow 1 Reputation point
2022-07-17T18:26:25.817+00:00

Sometimes GetCharRect return a negative or positive infinity for the top,right bottom and left positions.
Is there a way to get the rectangle for a character at offest position from the start of the document without the CarorPosition having to point it or the offset position being selected?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,671 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
762 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. joe blow 1 Reputation point
    2022-07-17T18:33:00.9+00:00

    No matter what the offset value is top,right bottom and left positions
    richTextBox.CaretPosition.GetPositionAtOffset(163).GetCharacterRect(LogicalDirection.Forward) {Empty} System.Windows.Rect

    The Selection is an empty string.

    	richTextBox.Selection	{System.Windows.Documents.TextSelection}	System.Windows.Documents.TextSelection  
    	Text	""	string