Wednesday, January 28, 2009

WPF Text Decorations

Text Decorations :

Your Web page looks more attractive if it contains some decorative text. No one would like to read the contents those are not properly decorated. Some times you need to highlight a word or you want to make a word look little different than the other words on your page. Here are some examples that would help you to make your text decorative in WPF. You can do some Text decorations like Underline, StrikeThrough, Over Line, Base Line in WPF. This blogs shows how you can apply these different Text decorations to your web page. To understand all these you must have some idea about TextBlock Control. TextBlock Control is a lightweight control for displaying small amount of float content. You can drag and drop it from toolbox. You can decorate the text using XAML code and setting the property of it. You can also set the Text Decoration style from code bihind file also. Here I have provided both ways of doing. Use what ever is convenient for you.

Apply UnderLine :

XAML Code :

<TextBlock TextDecorations="UnderLine" VerticalAlignment="Center" HorizontalAlignment="Center" Name="tbTest">
Text Decorations
</TextBlock>

C# Code :

tbTest.TextDecorations = TextDecorations.UnderLine;

Apply OverLine :

XAML Code :

<TextBlock TextDecorations="Overline" VerticalAlignment="Center" HorizontalAlignment="Center" Name="tbTest">
Text Decorations
</TextBlock>

C# Code :

tbTest.TextDecorations = TextDecorations.Overline;


Apply BaseLine :

XAML Code :

<TextBlock TextDecorations="Baseline" VerticalAlignment="Center" HorizontalAlignment="Center" Name="tbTest">
Text Decorations
</TextBlock>

C# Code :

tbTest.TextDecorations = TextDecorations.Baseline;

Apply Strikethrough :

XAML Code :

<TextBlock TextDecorations="Strikethrough" VerticalAlignment="Center" HorizontalAlignment="Center" Name="tbTest">
Text Decorations
</TextBlock>

C# Code :

tbTest.TextDecorations = TextDecorations.Strikethrough;


1 comment: