Aracılığıyla paylaş


Nasıl yapılır: Metin Süslemesi Oluşturma

TextDecoration Nesne, metne ekleyebileceğiniz görsel bir süslemedir. Dört tür metin süslemesi vardır: altı çizili, taban çizgisi, üstü çizili ve üst çizgi. Aşağıdaki örnekte metin süslemelerinin metne göre konumları gösterilmektedir.

Diagram of text decoration types

Metne metin süslemesi eklemek için bir TextDecoration nesne oluşturun ve özelliklerini değiştirin. Metin düzenlemesinin Location nerede görüneceğini belirtmek için özelliğini kullanın(örneğin, altı çizili). Pen Düz dolgu veya gradyan rengi gibi metin dekorasyonunun görünümünü belirtmek için özelliğini kullanın. Özelliği için Pen bir değer belirtmezseniz, süslemeler varsayılan olarak metinle aynı renge sahip olur. Bir TextDecoration nesneyi tanımladıktan sonra, istediğiniz metin nesnesinin koleksiyonuna ekleyin TextDecorations .

Aşağıdaki örnek, doğrusal gradyan fırçası ve kesikli kalemle stillenmiş bir metin süslemesini gösterir.

Text decoration with linear gradient underline

Hyperlink nesnesi, akış içeriğinde köprü barındırmanıza olanak tanıyan satır içi düzeyde bir akış içerik öğesidir. Varsayılan olarak, Hyperlink bir TextDecoration alt çizgi görüntülemek için bir nesne kullanır. TextDecoration özellikle de çok sayıda Hyperlink nesneniz varsa, nesneleri örneklemek için yoğun performans kullanabilirsiniz. Öğeleri kapsamlı bir şekilde kullanıyorsanız Hyperlink , yalnızca olay gibi bir olayı tetiklerken alt çizgi göstermeyi MouseEnter düşünebilirsiniz.

Aşağıdaki örnekte, "MSN'im" bağlantısının altı dinamiktir; yalnızca olay tetiklendiğinde MouseEnter görünür.

Hyperlinks displaying TextDecorations

Daha fazla bilgi için bkz . Köprü altı çizili olup olmadığını belirtme.

Örnek

Aşağıdaki kod örneğinde, altı çizili metin dekorasyonu varsayılan yazı tipi değerini kullanır.

// Use the default font values for the strikethrough text decoration.
private void SetDefaultStrikethrough()
{
    // Set the underline decoration directly to the text block.
    TextBlock1.TextDecorations = TextDecorations.Strikethrough;
}
' Use the default font values for the strikethrough text decoration.
Private Sub SetDefaultStrikethrough()
    ' Set the underline decoration directly to the text block.
    TextBlock1.TextDecorations = TextDecorations.Strikethrough
End Sub
<!-- Use the default font values for the strikethrough text decoration. -->
<TextBlock
  TextDecorations="Strikethrough"
  FontSize="36" >
  The quick red fox
</TextBlock>

Aşağıdaki kod örneğinde, kalem için düz renk fırçasıyla bir alt çizgi metin süslemesi oluşturulur.

// 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>

Aşağıdaki kod örneğinde, kesikli kalem için doğrusal gradyan fırçasıyla bir alt çizgi metin süslemesi oluşturulur.

// 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>

Ayrıca bkz.