开发者

Can a TextPointer be created with a specified LogicialDirection?

开发者 https://www.devze.com 2023-01-26 00:31 出处:网络
I\'m having trouble getting desired behavior in a WPF RichTextBox.I am creating a Span in code and applying a format and I want to position the cursor after the Span (so newly typed text won\'t be for

I'm having trouble getting desired behavior in a WPF RichTextBox. I am creating a Span in code and applying a format and I want to position the cursor after the Span (so newly typed text won't be formatted). From the documentation, it sounds like:

editor.CaretPosition = span.ElementEnd.GetInsertionPosition(LogicalDirection.Forward) 

should give me the behavior I seek:

If the TextPointer already points to a valid insertion position, but the closing tag for a non-empty formatting sequence directly follows that position in the given direction, then the TextPointer returned by this method is adjusted to point to the insertion position just after the close of the formatting sequence.

But in practice I get a TextPointer wi开发者_运维技巧th Backward direction unless the last character is a space and Backward direction results in new text being formatted. I've tried some of the other, similar methods on TextPointer without success.


I was able to get it working by calling GetPositionAtOffset(0, LogicalDirection.Forward) on the TextPointer.

0

精彩评论

暂无评论...
验证码 换一张
取 消