PasswordBox.SelectionForeground Property

July 28, 2014

Gets or sets the brush used for the selected text in the PasswordBox.

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

public Brush SelectionForeground { get; set; }
<PasswordBox SelectionForeground="colorString"/>

XAML Values


Within opening and closing property elements for PasswordBox.SelectionForeground, 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.


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 used for the selected text in the PasswordBox.

Dependency property identifier field: SelectionForegroundProperty

Use the SelectionForeground property to change the foreground of the selected password in a password box control.

The following code snippet shows how you can use the SelectionForeground property to set the foreground of the selected password in a PasswordBox. This example is part of a larger example available in the PasswordBox class overview.

Security noteSecurity Note:

Avoid hard-coding a password within your source code.

<TextBlock Text="Demonstrating styles for PasswordBox" Margin="20,10,0,0" />
<TextBlock FontSize="18" Margin="20,10,0,0" TextWrapping="Wrap">
    Select the following password to view the results of setting the 
    SelectionForeground and SelectionBackground properties.
<PasswordBox Margin="20,10,0,0" Password="HelloWorld" Width="200" Height="70" 
             SelectionForeground="Black" HorizontalAlignment="Left">
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="Gray" Offset="0.0" />
            <GradientStop Color="White" Offset="1.0" />

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2014 Microsoft