TextBox.CaretBrush Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets the brush that is used to render the vertical bar that indicates the insertion point.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<TextBox> <TextBox.CaretBrush> singleBrush </TextBox.CaretBrush> </TextBox>
<TextBox CaretBrush="colorString"/>
XAML Values
Property Value
Type: System.Windows.Media.BrushA 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
Show: