In a WPF application, what are the similarities and differences between the textbox and textblock controls? The answer was posted on StackOverflow.com.
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.
Label
The Label is similar to the TextBlock in that you can use it to put read-only text on the screen. Generally, a Label is for short, one-line texts (but may include an image), while the TextBlock works well for multi-line strings, but can only contain text (strings).