Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Using XAML TextBlock
WhatsApp
Mahesh Chand
6y
35.9k
0
3
100
Article
XAML <TextBlock> element represents a TextBlock control.
The following code example is how a TextBox is declared in XAML.
<
TextBlock
Name
=
"TextBlock1"
Height
=
"30"
Width
=
"200"
Text
=
"Hello! I am a TextBlock."
Foreground
=
"Red"
>
</
TextBlock
>
The following code example sets margin and alignment of the control.
<
TextBlock
Name
=
"TextBlock1"
Height
=
"30"
Width
=
"200"
Text
=
"Hello! I am a TextBlock."
Margin
=
"10,10,0,0"
VerticalAlignment
=
"Top"
HorizontalAlignment
=
"Left"
>
</
TextBlock
>
The following code example sets TextBlock's font including font name, font size, and font styles.
FontSize
=
"14"
FontFamily
=
"Verdana"
FontWeight
=
"Bold"
The TextWrapping property sets the wrap of no wrap text.
TextWrapping
=
"Wrap"
The TextAlignment property sets the text alignment of text in the control.
TextAlignment
=
"Right"
The Padding property sets the space between a boundary and the text that can be applied to all sides or a selected side of the boundary. The padding spacing is based on left, right, top and bottom.
<
TextBlock
Name
=
"TextBlock1"
Height
=
"30"
Width
=
"200"
Text
=
"Hello! I am a TextBlock."
Foreground
=
"Red"
Margin
=
"10,10,0,0"
VerticalAlignment
=
"Top"
HorizontalAlignment
=
"Left"
FontSize
=
"14"
FontFamily
=
"Verdana"
FontWeight
=
"Bold"
TextWrapping
=
"Wrap"
TextAlignment
=
"Center"
Padding
=
"2"
>
</
TextBlock
>
The Inlines property represents the collection of inline text within the control.
<
Run
FontWeight
=
"Bold"
FontSize
=
"14"
Text
=
"Hi! I am a TextBlock. "
/>
<
Run
FontStyle
=
"Italic"
Foreground
=
"Red"
Text
=
"This is red text. "
/>
<
Run
FontStyle
=
"Italic"
FontSize
=
"18"
Text
=
"Here is some linear gradient text. "
>
<
Run.Foreground
>
<
LinearGradientBrush
>
<
GradientStop
Color
=
"Green"
Offset
=
"0.0"
/>
<
GradientStop
Color
=
"Purple"
Offset
=
"0.25"
/>
<
GradientStop
Color
=
"Orange"
Offset
=
"0.5"
/>
<
GradientStop
Color
=
"Blue"
Offset
=
"0.75"
/>
</
LinearGradientBrush
>
</
Run.Foreground
>
</
Run
>
<
Run
FontStyle
=
"Italic"
Foreground
=
"Green"
Text
=
"How about adding some green? "
/>
</
TextBlock.Inlines
>
For a detailed tutorial on WPF TextBlock, please visit
Working with TextBlock in WPF
.
XAML TextBlock
WPF TextBlock
Text Block XAML
Up Next
Ebook Download
View all
Programming XAML
Read by 12.3k people
Download Now!
Learn
View all
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.
Membership not found