标签和文本块之间的区别 [英] Difference between Label and TextBlock
问题描述
根据 与 Microsoft 合作开发 Windows 应用程序.NET 4 70-511 培训套件
Label
控件和 TextBlock
控件之间有什么区别,因为它们都是内容控件并且只显示文本?
What is the difference between the Label
control and TextBlock
control since both are content controls and just displaying text?
推荐答案
TextBlock 不是控件
即使 TextBlock
位于 System.Windows.Controls 命名空间中,它也不是控件.它直接派生自 FrameworkElement
.另一方面,标签派生自 ContentControl
.这意味着 Label
可以:
TextBlock is not a control
Even though TextBlock
lives in the System.Windows.Controls namespace, it is not a control. It derives directly from FrameworkElement
. Label, on the other hand, derives from ContentControl
. This means that Label
can:
- 获得一个自定义控件模板(通过
Template
属性). - 显示除字符串以外的数据(通过
Content
属性). - 将
DataTemplate
应用到其内容(通过ContentTemplate
属性). 做任何
ContentControl
可以做而FrameworkElement
做不到的事情.
- Be given a custom control template (via the
Template
property). - Display data other than just a string (via the
Content
property). - Apply a
DataTemplate
to its content (via theContentTemplate
property). Do whatever else a
ContentControl
can do that aFrameworkElement
cannot.
Label
文字在禁用时变灰标签
支持访问键Label
比TextBlock
重得多
Label
text is grayed out when disabledLabel
supports access keysLabel
is much heavier thanTextBlock
下面有一些更有趣的阅读
Some more interesting reads below
这篇关于标签和文本块之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!