Compartir a través de


PasswordBox.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; }
<PasswordBox>
  <PasswordBox.CaretBrush>
    singleBrush
  </PasswordBox.CaretBrush>
</PasswordBox>
<PasswordBox CaretBrush="colorString"/>

XAML Values

  • singleBrush
    Within opening and closing property elements for PasswordBox.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
The brush that is used to render the vertical bar that indicates the insertion point.

Remarks

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

Security noteSecurity Note:

Avoid hard-coding a password within your source code.

<StackPanel>
    <!--Setting the Caret to blue color-->
    <PasswordBox CaretBrush="Blue" Password="HelloWorld" />
    <!--Setting the Caret to red color-->
    <PasswordBox CaretBrush="Red" Password="HelloWorld" />
</StackPanel>
public void AddPWB()
{
    PasswordBox MyPW1 = new PasswordBox();
    MyPW1.Password = "HelloWorld";

    //Setting the color of the caret in the first password box to blue
    SolidColorBrush MyBrush1 = new SolidColorBrush();
    MyBrush1.Color = Colors.Blue;
    MyPW1.CaretBrush = MyBrush1;
    PasswordBox MyPW2 = new PasswordBox();
    MyPW2.Password = "HelloWorld";

    //Setting the color of the caret in the second password box to red
    SolidColorBrush MyBrush2 = new SolidColorBrush();
    MyBrush2.Color = Colors.Red;
    MyPW2.CaretBrush = MyBrush2;
    MySP.Children.Add(MyPW1);
    MySP.Children.Add(MyPW2);
}
Public Sub AddPWB()
    Dim MyPW1 As PasswordBox = New PasswordBox
    MyPW1.Password = "HelloWorld"

    'Setting the color of the caret in the first password box to blue
    Dim MyBrush1 As SolidColorBrush = New SolidColorBrush
    MyBrush1.Color = Colors.Blue
    MyPW1.CaretBrush = MyBrush1
    Dim MyPW2 As PasswordBox = New PasswordBox
    MyPW2.Password = "HelloWorld"

    'Setting the color of the caret in the second password box to red
    Dim MyBrush2 As SolidColorBrush = New SolidColorBrush
    MyBrush2.Color = Colors.Red

    MyPW2.CaretBrush = MyBrush2
    MySP.Children.Add(MyPW1)
    MySP.Children.Add(MyPW2)
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.