Freigeben über


TextBlock.TextDecorations Property

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

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)

Syntax

'Declaration
Public Property TextDecorations As TextDecorationCollection
public TextDecorationCollection TextDecorations { get; set; }
<object TextDecorations="Underline"/>

Property Value

Type: System.Windows.TextDecorationCollection
A TextDecorationCollection, or nulla null reference (Nothing in Visual Basic) if no text decorations are applied.

Remarks

Dependency property identifier field: TextDecorationsProperty

A text decoration is a visual ornament that you can add to text. WPF supports APIs that let you define a custom text decoration. Silverlight 5 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 name provides compatibility between Silverlight and WPF. The TextDecorationCollection object in Silverlight 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 nulla null reference (Nothing in Visual Basic). Setting the value to nulla null reference (Nothing in Visual Basic) 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.

Examples

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

<Grid x:Name="LayoutRoot" Background="White">
    <TextBlock Height="33" HorizontalAlignment="Left" Margin="47,109,0,0" Name="MyTBl" Text="Using TextDecorations property to underline the text." VerticalAlignment="Top" Width="308" />
</Grid>
Private Sub SetUnderline()
    MyTBl.TextDecorations = TextDecorations.Underline
End Sub
private void SetUnderline()
{
    MyTBl.TextDecorations = TextDecorations.Underline;
}

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.