Export (0) Print
Expand All

TextDecorations Property

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

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

Property Value

TextDecorations

A value of teh TextDecorations enumeration 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.

Simulating a Hyperlink using the TextDecorations Property

Simulating a Hyperlink using the TextDecorations Property

LineBreak is listed in the Applies To list for this property, because it does exist in the object model and you can get and set it. However, all LineBreak properties are ignored for rendering purposes.

Examples

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.

XAML
<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 defined in the previous XAML example:

JavaScript
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

See Also

Text and Fonts Overview
FontFamily
FontSize
FontStretch
FontStyle
FontWeight

Community Additions

Show:
© 2014 Microsoft