Partager via


TextDecorations

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

Gets or sets the text decoration for the content in this element.

<object TextDecorations="TextDecorations"  .../>
value = object.TextDecorations
object.TextDecorations = value

Property Value

Type: TextDecorations Enumeration

One of the enumeration values that specifies the desired text decoration.

This property is read/write. The default value is None.

Remarks

By using the TextDecorations property, you can create the visual appearance of a hyperlink in a Run or TextBlock object.

The "Applies To" section of this topic lists LineBreak, because it does exist in the object model and you can get and set it. However, all LineBreak properties are ignored for rendering purposes.

Example

The following XAML example shows how to define a TextBlock that simulates a hyperlink by displaying an underline in response to the MouseEnter event. The underline is removed in response to the MouseLeave event. Notice that the Cursor property is set to display the Hand cursor when the mouse pointer is over the TextBlock.

<TextBlock
  Text="Click to Win!"
  TextDecorations="None"
  Cursor="Hand"
  FontSize="14" FontWeight="Bold"
  MouseEnter="onMouseEnter"
  MouseLeave="onMouseLeave"
  MouseLeftButtonUp="onMouseLeftButtonUp" />

The following JavaScript example shows the corresponding event-handling functions for the TextBlock that is defined in the previous XAML example.

function onMouseEnter(sender, mouseEventArgs)
{
    sender.textDecorations = "Underline";
    sender.foreground="Maroon";
}

function onMouseLeave(sender, mouseEventArgs)
{
    sender.textDecorations = "None";
    sender.foreground="Black";
}

function onMouseLeftButtonUp(sender, mouseEventArgs)
{
    alert("Congratulations!");
}

Applies To

Run

TextBlock