Freigeben über


TextBox.CaretBrush Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Property CaretBrush As Brush
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 Silverlight 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.

Remarks

Dependency property identifier field: CaretBrushProperty.

Examples

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

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.