I have a WPF RichTextBox control that I want to behave like a normal RichTextBox in every way except that the user cannot edit the text and the caret is not visible. The issue I’m having is that when I change IsReadOnly to False, the RichTextBox stops reacting to keystrokes. I want it to respond normally to keystrokes like Home, End, PgUp, PgDn, Up, Down. The documentation doesn’t mention this behavior.
<RichTextBox
IsReadOnly="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
Width="65" Height="20">
<FlowDocument>
<Paragraph>
Line 1
Line 2
Line 3
</Paragraph>
</FlowDocument>
</RichTextBox>
I’ve tried adding an OnKeyDown event handler, but it doesn’t fire. I’ve watched the events in Snoop as I push keys with the RichTextBox in keyboard focus and no fired events are shown in Snoop. I’ve tried setting IsDocumentEnabled explicitly to True, but that also has no effect. I’ve tried wrapping the RichTextBox in a ScrollViewer, but this has no effect either.
Any suggestions for how I can maintain this RichTextBox as IsReadOnly=True, but get the expected keystroke behavior of a RichTextBox?
Set
IsReadOnlyCaretVisibleto TrueIf you don’t want the caret to be visible then set the
CaretBrushtoTransparent