TextBox.CaretBrush Property

May 11, 2014

Gets or sets the brush that is used to render the vertical bar that indicates the insertion point.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public Brush CaretBrush { get; set; }
<TextBox>
  <TextBox.CaretBrush>
    singleBrush
  </TextBox.CaretBrush>
</TextBox>
<TextBox CaretBrush="colorString"/>

XAML Values

singleBrush

Within opening and closing property elements for TextBox.CaretBrush, exactly one object element for an object that derives from Brush. The object element is typically one of the following Windows Phone classes: LinearGradientBrush, RadialGradientBrush, ImageBrush, SolidColorBrush, or VideoBrush.

colorString

The Color for a SolidColorBrush expressed as an attribute string. This can be a named color, an RGB value, or an ScRGB value. RGB or ScRGB may also specify alpha information. See Color.

Property Value

Type: System.Windows.Media.Brush
A brush that is used to render the vertical bar that indicates the insertion point.

Dependency property identifier field: CaretBrushProperty.

The following example sets the CaretBrush property for a TextBox in XAML, C#, and Visual Basic.


<StackPanel>
    <!--Setting the Caret to Blue color-->
    <TextBox CaretBrush="Blue" Text="HelloWorld" />
    <!--Setting the Caret to Green color-->
    <TextBox CaretBrush="Green" Text="HelloWorld" />
</StackPanel>



public void AddTB()
{
    TextBox MyTB1 = new TextBox();
    MyTB1.Text = "HelloWorld";

    //Setting the color of the caret in the first text box to blue
    SolidColorBrush MyBrush1 = new SolidColorBrush();
    MyBrush1.Color = Colors.Blue;
    MyTB1.CaretBrush = MyBrush1;
    TextBox MyTB2 = new TextBox();
    MyTB2.Text = "HelloWorld";

    //Setting the color of the caret in the second text box to green
    SolidColorBrush MyBrush2 = new SolidColorBrush();
    MyBrush2.Color = Colors.Green;
    MyTB2.CaretBrush = MyBrush2;
    MySP.Children.Add(MyTB1);
    MySP.Children.Add(MyTB2);
}



Public Sub AddTB()
    Dim MyTB1 As TextBox = New TextBox
    MyTB1.Text = "HelloWorld"

    'Setting the color of the caret in the first text box to blue
    Dim MyBrush1 As SolidColorBrush = New SolidColorBrush
    MyBrush1.Color = Colors.Blue
    MyTB1.CaretBrush = MyBrush1
    Dim MyTB2 As TextBox = New TextBox
    MyTB2.Text = "HelloWorld"

    'Setting the color of the caret in the second text box to green
    Dim MyBrush2 As SolidColorBrush = New SolidColorBrush
    MyBrush2.Color = Colors.Green
    MyTB2.CaretBrush = MyBrush2
    MySP.Children.Add(MyTB1)
    MySP.Children.Add(MyTB2)
End Sub


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft