Difference between Label and TextBlock

前端 未结 5 2077
小鲜肉
小鲜肉 2020-11-30 19:40

According to the Windows Applications Development with Microsoft .NET 4 70-511 Training Kit

What is the difference between the Label control and T

5条回答
  •  自闭症患者
    2020-11-30 20:12

    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. 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 text is grayed out when disabled
      • Label supports access keys
      • Label is much heavier than TextBlock

    Source

    Some more interesting reads below

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

提交回复
热议问题