Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBox Caret Styling

Tags:

I've found a few things on setting CaretBrushes in WPF4, but has anybody actually ever changed the caret itself?

What I'd like to do is use the OVERWRITE caret in INSERT mode. I've seen a hack from .Net 3.5 times, but it is unperformant and lacks behind actual cursor movement...

It would be great if the Caret had a Template - That would be consistent with the whole WPF idea...

Any advice?

like image 924
Sebastian Edelmeier Avatar asked Feb 15 '12 09:02

Sebastian Edelmeier


People also ask

How to style caret?

It can even be animated. /* Keyword value */ caret-color: auto; color: transparent; color: currentColor; /* <color> values */ caret-color: red; caret-color: #5729e9; caret-color: rgb(0, 200, 0); caret-color: hsla(228, 4%, 24%, 0.8);

What is WPF CaretBrush?

XAML Values CaretBrush, exactly one object element for an object that derives from Brush. The object element is typically one of the following Silverlight classes: LinearGradientBrush, RadialGradientBrush, ImageBrush, SolidColorBrush, or VideoBrush.

What is caret brush?

By Ajay May 22, 2022. Caret browsing is a feature in Microsoft Windows that allows a user to navigate and select text on a web page using only their keyboard. This feature brings up a blinking cursor on web pages, using which you can select, and highlight texts and images. Table of Contents.


1 Answers

The CaretElement is an internal sealed class and not possible to customize through a data template for example. At least, the caret brush is possible to change.

<TextBox Text="This is some random text" CaretBrush="Blue" /> 

If you want to have a linear gradient on the caret brush, this can be done.

<TextBox Text="This is some random text" FontSize="20">         <TextBox.CaretBrush>             <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">                 <LinearGradientBrush.GradientStops>                     <GradientStop Color="Blue" Offset="0" />                     <GradientStop Color="Red" Offset="1" />                 </LinearGradientBrush.GradientStops>             </LinearGradientBrush>         </TextBox.CaretBrush> 

I tried using a Visual Brush also, but the caret is always being shown as a small vertical line.

like image 67
Tore Aurstad Avatar answered Sep 25 '22 01:09

Tore Aurstad