How to set background color on TextBlock

Steve Wood 56 Reputation points

How can the background color on a TextBlock control be changed?

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. macintoshpro 36 Reputation points

    TextBlock don't have background property, but you can put it inside a Grid and set background for grid

    1 person found this answer helpful.

  2. Steve Wood 56 Reputation points

    Ah...right...a child control inherits some of the visual attributes of the parent. So, I can put the TextBlock in one of the panels such as a Canvas or ItemsPanel and set the background on the panel. Sure is humongous overhead just to set the background of a control.

    0 comments No comments

  3. Roy Li - MSFT 32,721 Reputation points Microsoft Vendor


    TextBlock derives from FrameworkElement and there is no background property for FrameworkElement. So there is no background property for the Textblock class.
    Generally, we will provide the background effect with an additional element looks like a container for the TextBlock. For example, we could use Border or Grid like @macintoshpro mentioned in his reply.

    If you are using border, it looks like this:

    <Border Background="Red">  

    Thank you.