共用方式為


TextDecoration 建構函式

定義

初始化 TextDecoration 類別的新執行個體。

多載

TextDecoration()

初始化 TextDecoration 類別的新執行個體。

TextDecoration(TextDecorationLocation, Pen, Double, TextDecorationUnit, TextDecorationUnit)

使用指定的 TextDecorationLocationPenPenOffsetPenOffsetUnit 值,初始化 PenThicknessUnit 類別的新執行個體。

TextDecoration()

初始化 TextDecoration 類別的新執行個體。

public:
 TextDecoration();
public TextDecoration ();
Public Sub New ()

範例

下列程式碼範例示範如何使用無參數建構函式建立 TextDecoration

// Use a Red pen for the underline text decoration.
private void SetRedUnderline()
{
    // Create an underline text decoration. Default is underline.
    TextDecoration myUnderline = new TextDecoration();

    // Create a solid color brush pen for the text decoration.
    myUnderline.Pen = new Pen(Brushes.Red, 1);
    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);
    TextBlock2.TextDecorations = myCollection;
}
' Use a Red pen for the underline text decoration.
Private Sub SetRedUnderline()
    ' Create an underline text decoration. Default is underline.
    Dim myUnderline As New TextDecoration()

    ' Create a solid color brush pen for the text decoration.
    myUnderline.Pen = New Pen(Brushes.Red, 1)
    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)
    TextBlock2.TextDecorations = myCollection
End Sub
<!-- Use a Red pen for the underline text decoration -->
<TextBlock
  FontSize="36" >
  jumps over
  <TextBlock.TextDecorations>
    <TextDecorationCollection>
      <TextDecoration 
        PenThicknessUnit="FontRecommended">
        <TextDecoration.Pen>
          <Pen Brush="Red" Thickness="1" />
        </TextDecoration.Pen>
      </TextDecoration>
    </TextDecorationCollection>
  </TextBlock.TextDecorations>
</TextBlock>

備註

屬性的 Location 預設值為 Underline

適用於

TextDecoration(TextDecorationLocation, Pen, Double, TextDecorationUnit, TextDecorationUnit)

使用指定的 TextDecorationLocationPenPenOffsetPenOffsetUnit 值,初始化 PenThicknessUnit 類別的新執行個體。

public:
 TextDecoration(System::Windows::TextDecorationLocation location, System::Windows::Media::Pen ^ pen, double penOffset, System::Windows::TextDecorationUnit penOffsetUnit, System::Windows::TextDecorationUnit penThicknessUnit);
public TextDecoration (System.Windows.TextDecorationLocation location, System.Windows.Media.Pen pen, double penOffset, System.Windows.TextDecorationUnit penOffsetUnit, System.Windows.TextDecorationUnit penThicknessUnit);
new System.Windows.TextDecoration : System.Windows.TextDecorationLocation * System.Windows.Media.Pen * double * System.Windows.TextDecorationUnit * System.Windows.TextDecorationUnit -> System.Windows.TextDecoration
Public Sub New (location As TextDecorationLocation, pen As Pen, penOffset As Double, penOffsetUnit As TextDecorationUnit, penThicknessUnit As TextDecorationUnit)

參數

location
TextDecorationLocation

文字裝飾的位置。

pen
Pen

用於繪製文字裝飾的 Pen。 如果這個值為 null,則文字裝飾顏色與套用到的文字顏色相符,且文字裝飾的粗細會設定為字型的建議粗細。

penOffset
Double

文字裝飾位置的垂直替代。 負值會向下移動裝飾,而正值會向上移動裝飾。

penOffsetUnit
TextDecorationUnit

用於解譯 penOffset 值的單位。

penThicknessUnit
TextDecorationUnit

用於解譯 penThickness 值的單位。

範例

下列程式碼範例示範如何使用 、、、 和 參數建立 TextDecoration locationpenThicknessUnit penOffsetUnit penOffset pen

// Use a Maroon pen for the baseline text decoration.
private void SetMaroonBaseline()
{
    // Create an baseline text decoration 2 units lower than the default.
    TextDecoration myBaseline = new TextDecoration(
            TextDecorationLocation.Baseline,
            new Pen(Brushes.Maroon, 1),
            2.0,
            TextDecorationUnit.Pixel,
            TextDecorationUnit.Pixel);

    // Set the baseline decoration to a TextDecorationCollection and add it to the text block.
    TextDecorationCollection myCollection = new TextDecorationCollection();
    myCollection.Add(myBaseline);
    TextBlock2.TextDecorations = myCollection;
}
' Use a Maroon pen for the baseline text decoration.
Private Sub SetMaroonBaseline()
    ' Create an baseline text decoration 2 units lower than the default.
    Dim myBaseline As New TextDecoration(TextDecorationLocation.Baseline, New Pen(Brushes.Maroon, 1), 2.0, TextDecorationUnit.Pixel, TextDecorationUnit.Pixel)

    ' Set the baseline decoration to a TextDecorationCollection and add it to the text block.
    Dim myCollection As New TextDecorationCollection()
    myCollection.Add(myBaseline)
    TextBlock2.TextDecorations = myCollection
End Sub
<TextBlock>
  <TextBlock.TextDecorations>
    <TextDecoration Location="Baseline" PenOffset="2" PenOffsetUnit="Pixel" PenThicknessUnit="Pixel" >
      <TextDecoration.Pen>
        <Pen Brush="Maroon" Thickness="1" />
      </TextDecoration.Pen>
    </TextDecoration>
  </TextBlock.TextDecorations>
  The quick red fox
</TextBlock>

適用於