标签和文本块之间的区别 [英] Difference between Label and TextBlock

查看:24
本文介绍了标签和文本块之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 与 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:

  1. 获得一个自定义控件模板(通过 Template 属性).
  2. 显示除字符串以外的数据(通过 Content 属性).
  3. DataTemplate 应用到其内容(通过 ContentTemplate 属性).
  4. 做任何 ContentControl 可以做而 FrameworkElement 做不到的事情.

  1. Be given a custom control template (via the Template property).
  2. Display data other than just a string (via the Content property).
  3. Apply a DataTemplate to its content (via the ContentTemplate property).
  4. Do whatever else a ContentControl can do that a FrameworkElement cannot.

  • Label文字在禁用时变灰
  • 标签支持访问键
  • LabelTextBlock
  • 重得多
  • Label text is grayed out when disabled
  • Label supports access keys
  • Label is much heavier than TextBlock

来源

下面有一些更有趣的阅读

Some more interesting reads below

这篇关于标签和文本块之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆