Text decoration in WPF Using VB.NET

This article defines the text with underline decoration with dashes, overline decoration with dashes and underlinedecoration in WPF and XAML.
  • 4191

This article defines the text with underline decoration with dashes, overline decoration with dashes and underlinedecoration in WPF and XAML.

TextDecorations - A text decoration is a visual ornament that you can add to text.

Underline decoration with dashes

Now Drag and drop a TextBlock control on the form.

XAML code

<Window x:Class="MainWindow"

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

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

    Title="MainWindow" Height="350" Width="525">

    <StackPanel>

        <TextBlock FontSize="24" Width="180" VerticalAlignment="Center">

        Rohatash Kumar

        <TextBlock.TextDecorations>

          <TextDecoration Location="Underline"

            PenThicknessUnit="FontRecommended">

            <TextDecoration.Pen>

              <Pen Brush="Red" Thickness="1">

                <Pen.DashStyle>

                  <DashStyle Dashes="5"/>

                </Pen.DashStyle>

              </Pen>

            </TextDecoration.Pen>

          </TextDecoration>

        </TextBlock.TextDecorations>

        </TextBlock>

 

    </StackPanel>

</Window>

The form looks like this.

td0.gif

Figure1.gif

Overline decoration with dashes

The below code defines the Overline decoration with dashes in XAML.

XAML code

<StackPanel>

        <TextBlock FontSize="24" Width="180" VerticalAlignment="Center">Rohatash Kumar

        <TextBlock.TextDecorations>

          <TextDecoration Location="OverLine"

            PenThicknessUnit="FontRecommended">

            <TextDecoration.Pen>

              <Pen Thickness="3">

                <Pen.Brush>

                  <LinearGradientBrush

                    StartPoint="0,0.5"  EndPoint="1,0.5">

                    <LinearGradientBrush.GradientStops>

                      <GradientStop Color="LimeGreen" Offset="0" />

                      <GradientStop Color="Yellow" Offset="1" />

                    </LinearGradientBrush.GradientStops>

                  </LinearGradientBrush>

                </Pen.Brush>

                <Pen.DashStyle>

                   <DashStyle  Dashes="0.5, 3, 1, 2" />

                </Pen.DashStyle>

              </Pen>

            </TextDecoration.Pen>

          </TextDecoration>

        </TextBlock.TextDecorations>

        </TextBlock>

    </StackPanel>

The form looks like this.

td1.gif

Figure2.gif

underline decoration

The below code defines the underline decoration in XAML.

XAML code

<Window x:Class="MainWindow"

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

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

    Title="MainWindow" Height="350" Width="525">

    <Grid >

    <TextBlock TextDecorations=" underline" Height="23" FontWeight="Bold" HorizontalAlignment="Left" Margin="10,10,0,0" Name="TextBlock1" Text="Rohatash Kumar" VerticalAlignment="Top" FontFamily="Verdana" Foreground="Blue" />

    </Grid>

</Window>

The window form looks like this.

td2.gif

Figure3.gif          

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.