Text decorations in WPF: Top, middle, underline, and baseline

Source: Internet
Author: User
Tags xmlns

We know that the modification of the text includes: Hollow words, three-dimensional words, crossed words, shadow words, bold, tilt and so on. Here only the style of the underlined words, the position of the underlined, we can divide it into: underlined, underlined, baseline and underline. As shown in figure:

Top to bottom, underlined (overline), underlined (strikethrough), baselines (Baseline), and underscores (underline).

How to achieve it?

(1) XAML Code:

<page 

xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

xmlns:x= "http:// Schemas.microsoft.com/winfx/2006/xaml ">
<textblock textdecorations=" strikethrough "FontSize= 

" Fontfamily= "Arial" >A</TextBlock>
</Page>

The TextDecorations property can be set to: Overline, Strikethrough, Baseline, underline, or none, default to None if the TextDecorations property is not set. That is, no dash decoration.

(2) using C # code:

private void Setdefaultstrikethrough ()

{

Textblock1.textdecorations = Textdecorations.strikethrough;

}

(For simplicity, only relevant key code is listed here, and other code is not listed in C #.) TextBlock1 is the name of the TextBlock and is marked with the X:name= "TextBlock1" form in XAML

If you want a more complex point of effect, such as the need to set the color of the dash, line thickness, and so on, the following figure:

How do you make a similar effect?

Set the TextDecorations property of the TextBlock, and then set the Pen property for TextDecoration.

The following XAML code:

<page xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http://schemas.microsoft.com /winfx/2006/xaml "> <Canvas> <textblock fontsize=" fontfamily= "Arial Black" margin= "0,0" > <
 Textblock.textdecorations> <textdecoration penoffset= "Ten" penoffsetunit= "Pixel" penthicknessunit= "Pixel" > <TextDecoration.Pen> <pen thickness= "5" > <Pen.Brush> <lineargradi
                  Entbrush opacity= "0.8" 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= "1,2,3"/> </pen . Dashstyle> </Pen> </textdecoration.pen> </TextDecoration> </TextBlock.TextDecorations> Good </TextBlock> </ Canvas> </Page>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.