WPF TextBlock 和 TextBox 之间有什么区别吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18204245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any difference between WPF TextBlock and TextBox?
提问by Irfan
What criteria must I consider when selecting one of these two controls?
在选择这两个控件之一时,我必须考虑什么标准?
回答by Rohit
Common to both TextBlocks and TextBoxes:
TextBlocks 和 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.
- 用于以排版方式显示更集中的文本。
- 可以包含设置为不同颜色、字体和大小的文本。
- 也可以从默认设置增加行高,以在每行文本之间留出更多空间。
- 用户无法选择 TextBlock 中的文本。
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.
- 用于显示更专注于内容输入的文本,或者当需要用户选择内容时。
- 只能设置为一种颜色、一种字体大小、一种字体类型等。
- 有固定的行距。
- 也可以设置为固定的高度和宽度,但也可以打开滚动条以允许内容扩展。
回答by Vidas Vasiliauskas
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.
TextBlock 是用于显示文本的更轻量级的控件,当您需要用户输入或编辑现有文本时使用 TextBox。内存使用证明。