SelectionBackground Property

TextBox.SelectionBackground 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 fills the background of the selected text.

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

public Brush SelectionBackground { get; set; }
<TextBox SelectionBackground="colorString"/>

XAML Values


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 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 that fills the background of the selected text.

Dependency property identifier field: SelectionBackgroundProperty.

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

The following code snippet shows how you can use the SelectionBackground property to set the background of the selected text in a TextBox. This example is part of a larger example available in the TextBox class overview.

<TextBlock Margin="20,40,0,0" Text="Demonstrating styles for TextBox" />

<TextBlock Margin="20,0,0,0" TextWrapping="Wrap">
    Select the following text to view the results of SelectionForeground and SelectionBackground properties.

<TextBox Text="Styles" Margin="20,5,0,0" HorizontalAlignment="Left" Width="200" Height="70" Foreground="White" Background="Black" BorderBrush="White" SelectionForeground="Black">
        <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

© 2017 Microsoft