Label和TextBlock之间的区别 [英] Difference between Label and TextBlock

查看:327
本文介绍了Label和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:

  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禁用时文本显示为灰色
  • Label支持访问键
  • LabelTextBlock
  • 重得多
  • Label text is grayed out when disabled
  • Label supports access keys
  • Label is much heavier than TextBlock

来源

下面一些更有趣的读物

  • http://www.wpfwiki.com/WPF%20Q4.1.ashx
  • What is the difference between the WPF TextBlock element and Label control?

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

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