Search code examples
wpftextboxtext-cursor

Hide caret in WPF TextBox


Is there a way to hide the cursor in a WPF textbox? I know there is Cursor="None" but that only affects the mouse cursor. I want to hide the "text cursor".


Solution

  • Caret is the current insert position in a text editor. Cursor is the shape of the mouse cursor.

    There is no way to disable the caret in a read-write TextBox. Instead, change the CaretBrush to be transparent.

    TextBox txt = ...;
    // Hide the caret.
    txt.CaretBrush = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
    // Show the caret.
    txt.CaretBrush = null;  // use default Brush