TextDecorations Property

TextBlock.TextDecorations Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets a value that specifies the text decorations that are applied to the content in a TextBlock element.

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

public TextDecorationCollection TextDecorations { get; set; }
<object TextDecorations="Underline"/>

Property Value

Type: System.Windows.TextDecorationCollection
A TextDecorationCollection, or null if no text decorations are applied.

Dependency property identifier field: TextDecorationsProperty

A text decoration is a visual ornament that you can add to text. Windows Phone supports only one type of text decoration: Underline. The type name of type used to set this property (TextDecorationCollection) suggests multiple possible values, but only one value is supported. The TextDecorationCollection object in Windows Phone supports only object. It does support Collection interface APIs or a public constructor.

In XAML, you can set TextDecorations to the value Underline or to an empty string (equivalent to no underline).

In code, you can set the value of TextBlock.TextDecorations to Underline or to null. Setting the value to null effectively restores the default value if it has been set to Underline in XAML or code previously .

TextDecorations settings for Run child elements override this top-level setting.

The following code example shows how you can use the TextDecorations property to underline the text in a TextBlock.


<Grid x:Name="LayoutRoot" Background="Transparent">
    <TextBlock HorizontalAlignment="Left" Margin="47,109,0,0" 
               Name="MyTBl" 
               Text="Using TextDecorations property to underline the text." TextWrapping="Wrap"
               VerticalAlignment="Top" />
</Grid>



private void SetUnderline()
{
    MyTBl.TextDecorations = TextDecorations.Underline;
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2016 Microsoft