TextDecoration.Pen TextDecoration.Pen TextDecoration.Pen TextDecoration.Pen Property

定義

文字装飾を描画するために使用される Pen を取得または設定します。Gets or sets the Pen used to draw the text decoration.

public:
 property System::Windows::Media::Pen ^ Pen { System::Windows::Media::Pen ^ get(); void set(System::Windows::Media::Pen ^ value); };
public System.Windows.Media.Pen Pen { get; set; }
member this.Pen : System.Windows.Media.Pen with get, set
Public Property Pen As Pen

プロパティ値

文字装飾の描画に使用される PenThe Pen used to draw the text decoration. この値がnullの場合、装飾の色は適用されるテキストと一致し、装飾の太さはフォントの推奨される太さに設定されます。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.
Private Sub SetLinearGradientUnderline()
    ' Create an underline text decoration. Default is underline.
    Dim myUnderline As New TextDecoration()

    ' Create a linear gradient pen for the text decoration.
    Dim myPen As 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.
    Dim myCollection As New TextDecorationCollection()
    myCollection.Add(myUnderline)
    TextBlock3.TextDecorations = myCollection
End Sub
<!-- 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>

注釈

次の例では、線状グラデーションブラシと破線のペンでスタイルを付けたテキスト装飾を示します。The following example shows a text decoration that has been styled with a linear gradient brush and a dashed pen.

線状グラデーション下線付きの文字装飾Text decoration with linear gradient underline
線状グラデーションブラシと破線ペンを使用してスタイルを付けた下線の例Example of an underline styled with a linear gradient brush and dashed pen

依存プロパティ情報Dependency Property Information

識別子フィールドIdentifier field PenProperty
メタデータプロパティがに設定されるtrueMetadata properties set to true NoneNone

適用対象

こちらもご覧ください