开发者

WPF set CaretPosition at start of a RichTextBox

开发者 https://www.devze.com 2023-02-22 19:04 出处:网络
I have a RichTextBox in my WPF app, filled with colored text. I want to make it programmatically go to the start of the document, so I followed msdn\'s recommandation:

I have a RichTextBox in my WPF app, filled with colored text. I want to make it programmatically go to the start of the document, so I followed msdn's recommandation:

    TextPointer caretPos = RTB.CaretPosition;
    caretPos = caretPos.DocumentStart;
    RTB.CaretPosition = caretPos;    

And that does precisely nothing...

I also tried:

RTB.Selection.Select(RTB.Document.ContentStart, RTB.Document.ContentStart);

Which didn't work either.

I couldn't find other information on the subject aside from another question in StackOVerflow, that remains unans开发者_JAVA技巧wered.

Anyone has a solution?


I thought it would be this:

rtb.CaretPosition = rtb.Document.ContentStart;

Seems to work for me.


Simple solution, don't touch the Caret! RTB.ScrollToHome(); did the deed.

0

精彩评论

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

关注公众号