Partager via


PasswordBox.SelectionBackground Property

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

Gets or sets the brush used to render the background for the selected text.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property SelectionBackground As Brush
public Brush SelectionBackground { get; set; }
<PasswordBox>
  <PasswordBox.SelectionBackground>
    singleBrush
  </PasswordBox.SelectionBackground>
</PasswordBox>
<PasswordBox SelectionBackground="colorString"/>

XAML Values

  • singleBrush
    Within opening and closing property elements for object.SelectionBackground, 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 fills the background of the selected text.

Remarks

Dependency property identifier field: SelectionBackgroundProperty

Use the SelectionBackground property to change the background of the selected password in the password box control.

Examples

The following code snippet shows how you can use the SelectionBackground property to set the background 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="11" Margin="20,10,0,0">
    Select the following password to view the results of setting the SelectionForeground and SelectionBackground properties.
</TextBlock>
<PasswordBox Margin="20,10,0,0" Password="HelloWorld" Width="200" Height="35" SelectionForeground="Black" HorizontalAlignment="Left">
    <PasswordBox.SelectionBackground>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="Gray" Offset="0.0" />
            <GradientStop Color="White" Offset="1.0" />
        </LinearGradientBrush>
    </PasswordBox.SelectionBackground>
</PasswordBox>

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.