Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between WPF TextBlock and TextBox?

What criteria must I consider when selecting one of these two controls?

like image 767
Irfan Avatar asked Aug 13 '13 08:08

Irfan


People also ask

What is the difference between label and TextBlock in WPF?

Labels usually support single line text output while the TextBlock is intended for multiline text display. For example in wpf TextBlock has a property TextWrapping which enables multiline input; Label does not have this. Label has an arbitrary Content property.

What is WPF TextBlock?

The WPF TextBlock control is a lightweight text editor control for displaying and formattting small amount of text flow content. The code examples in this tutorial demonstrates how to use a TextBlock control in WPF using XAML and C#. Creating a TextBlock. The TextBlock element represents a WPF TextBlock control in XAML ...

Is TextBlock editable?

TextBlock is not editable.

What is TextBlock?

Text block is the primary control for displaying read-only text in apps. You can use it to display single-line or multi-line text, inline hyperlinks, and text with formatting like bold, italic, or underlined.


2 Answers

Common to both TextBlocks and TextBoxes:

  • Can be used to display text
  • Can be set to specific Height and Width or be set to Auto so that they grow in size with the text.
  • Can set font size, font type, font styling, to wrap and to range left, right or centred.
  • Can have opacity set and have Pixel Shaders applied.

TextBlock:

  • Used for displaying text more focused typographically.
  • Can contain text set to different colors, fonts and sizes.
  • The line height can also be increased from the default setting to give more space between each line of text.
  • Text inside a TextBlock cannot be made selectable by the user.

TextBox:

  • Used for displaying text more focused for content input or when content is needed to be made selectable by the user.
  • Can only be set to one colour, one font size, one font type etc.
  • Have fixed Line Spacing.
  • Can also be set to a fixed height and width but also have scrollbars switched on to allow content to expand.
like image 69
Rohit Avatar answered Sep 22 '22 01:09

Rohit


TextBlock is more lightweight control for displaying text and TextBox is used when you require user input or edit existing text. Proof for mem usage.

like image 28
VidasV Avatar answered Sep 22 '22 01:09

VidasV