title: Why TextBlock is not sizing to its content?
body: <p>Why is the following <code>TextBlock</code> not sizing to its content? Its width (as shown with blue backgroud) is covering the width of the entire window.</p>
  <p>What am I missing here and how can I fix it?</p>
  <p>I have set <code>Width=&quot;Auto&quot;</code> for the textblock. NOTE: I don't want to set the entire window to <code>SizeToContent=&quot;WidthAndHeight&quot;</code> since it would have other controls that we don't need to use this setting for. This is just a minimal demo for this post only:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Page x:Class=&quot;WPTEST.HomePage&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
        xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; 
        xmlns:local=&quot;clr-namespace:WPF_TEST&quot;
        mc:Ignorable=&quot;d&quot; 
        d:DesignHeight=&quot;450&quot; d:DesignWidth=&quot;800&quot;
        Title=&quot;HomePage&quot;&gt;
  
      &lt;Grid&gt;
          &lt;StackPanel VerticalAlignment=&quot;Center&quot;&gt;
              &lt;TextBlock Width=&quot;Auto&quot; FontSize=&quot;16&quot; Background=&quot;Blue&quot; Foreground=&quot;White&quot; FontWeight=&quot;Bold&quot; Text=&quot;Welcome To Home Page. Your home page to perform main tasks&quot;/&gt;
          &lt;/StackPanel&gt;        
      &lt;/Grid&gt;
  &lt;/Page&gt;
  </code></pre>
  <p><strong>MainWindow Display</strong>:</p>
  <p><a href="https://i.stack.imgur.com/vOdlW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vOdlW.png" alt="enter image description here" /></a></p>