Search code examples
c#wpftextboxcaret

Is there a way to show caret in a disabled textbox?


I want all the disabled textboxes in my application to have carets in them when they are focused. This would allow users to select and copy part of the text without using a mouse.

I'm ok with writing templates. I have tried IsReadOnly instead of IsEnabled but readonly doesn't show carets either. Carets only need to be shown when the user focuses on the textbox same as the default behavior of a non-readonly enabled textbox.

I'm not sure if this is even possible so any advice is appreciated.


Solution

  • Ok, so all I had to do was to set IsReadOnlyCaretVisible to true.

    In order for it to affect all the textboxes in my application I've added fallowing code to my AppStyle.xml

    <Style TargetType="TextBox">
        <Setter Property="IsReadOnlyCaretVisible" Value="True"></Setter>
    </Style>