www.TLCube.com

Tag: XAML

Textbox caret

by TLCube on Feb.15, 2010, under Programming

If you are using dark colors your applications, there is possibly that TextBox caret is color is black. This will make editing TextBox text more difficult. TextBox caret color is inverse to backround color, but when backround color is set to null, the default black color is used (picture 1).

There is couple of workarounds. The simplest is set TextBox backround color same color as where parent color is (picture 2). There is another workaround here.

Now WPF 4.0 has new CaretBrush property. You can simply set caret color just like any other colors (Picture 3).

<TextBox Name="textBox3" CaretBrush="Orange"/><code>

You can also specify a more complex brush like a LinearGradient (picture 4):

            <TextBox.CaretBrush>
                <LinearGradientBrush StartPoint="0,0"
                         EndPoint="0,1">
                    <GradientStop Color="White"
                    Offset="0" />
                    <GradientStop Color="Orange"
                    Offset=".5" />
                    <GradientStop Color="White"
                    Offset="1" />
                </LinearGradientBrush>
            </TextBox.CaretBrush>

Time to say goodbye for caret problems.

TextBox caret demo
TextBox caret demo
TextBoxCaret.zip
58.7 KiB
7 Downloads
Details...

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...