RichTextBox and Inserting at Caret Positions

后端 未结 3 1164
感动是毒
感动是毒 2021-01-18 15:29

Here is the deal: I have a RichTextBox control and it works fine. The problem is that there is a button \"Insert Current DateTime\" which adds/injects the current datetime i

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-18 16:08

    I tried this solution with WPFToolkit.Extended RichTextBox and it didn't work for me. However I found another one and thought it would be good to post it in here in case someone else could use it.

    My problem was also that the after I clicked a button that is supposed to append text at the caret location, it instead adds it at the beginning of the RichTextBox.

    So The solution I found is similar to the one in here -

    RichTextBox CaretPosition physical location

    Instead of using CaretPosition I used RichTextBox.Selection.Start.InsertTextInRun("SomeText").

    It considered the selection's start as the caret position even though no selection was made and therefore was good enough for me.

    I hope someone will find this useful :)

提交回复
热议问题