如何在 RichTextBox 中获取选择的方向?

How to get the direction of a selection in a RichTextBox?

RichTextBox 中的文本用户可以select 向前或向后文本。如何以编程方式确定 selection 的方向? (EndStartLogicalDirection不表示这个)

您可以将 CaretPosition 与当前的 Selection 进行比较以确定文本是从哪个方向选择的:

TextPointer caretPos = richTextBox.CaretPosition;
TextPointer selectStart = richTextBox.Selection.Start;
TextPointer selectEnd = richTextBox.Selection.End;

if(caretPos.CompareTo(selectStart) == 0)
{
    //The text was selected from right to left.
}
else if(caretPos.CompareTo(selectEnd) == 0)
{
    //The text was selected from left to right.
}