This documentation is archived and is not being maintained.
TextDecoration.Pen Property
Visual Studio 2008
Gets or sets the Pen used to draw the text decoration. This is a dependency property.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
'Declaration Public Property Pen As Pen 'Usage Dim instance As TextDecoration Dim value As Pen value = instance.Pen instance.Pen = value
<object> <object.Pen> <Pen .../> </object.Pen> </object>
Property Value
Type: System.Windows.Media.PenThe Pen used to draw the text decoration. If this value is null, the decoration color matches the text to which it is applied and the decoration's thickness is set to the font's recommended thickness.
In the following code example, an underline text decoration is created with a linear gradient brush for the dashed pen.
// Use a linear gradient pen for the underline text decoration. private void SetLinearGradientUnderline() { // Create an underline text decoration. Default is underline. TextDecoration myUnderline = new TextDecoration(); // Create a linear gradient pen for the text decoration. Pen myPen = new Pen(); myPen.Brush = new LinearGradientBrush(Colors.Yellow, Colors.Red, new Point(0, 0.5), new Point(1, 0.5)); myPen.Brush.Opacity = 0.5; myPen.Thickness = 1.5; myPen.DashStyle = DashStyles.Dash; myUnderline.Pen = myPen; myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended; // Set the underline decoration to a TextDecorationCollection and add it to the text block. TextDecorationCollection myCollection = new TextDecorationCollection(); myCollection.Add(myUnderline); TextBlock3.TextDecorations = myCollection; }
<!-- Use a linear gradient pen for the underline text decoration. --> <TextBlock FontSize="36">the lazy brown dog. <TextBlock.TextDecorations> <TextDecorationCollection> <TextDecoration PenThicknessUnit="FontRecommended"> <TextDecoration.Pen> <Pen Thickness="1.5"> <Pen.Brush> <LinearGradientBrush Opacity="0.5" StartPoint="0,0.5" EndPoint="1,0.5"> <LinearGradientBrush.GradientStops> <GradientStop Color="Yellow" Offset="0" /> <GradientStop Color="Red" Offset="1" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Pen.Brush> <Pen.DashStyle> <DashStyle Dashes="2"/> </Pen.DashStyle> </Pen> </TextDecoration.Pen> </TextDecoration> </TextDecorationCollection> </TextBlock.TextDecorations> </TextBlock>
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show:
