title: Why does WPF "height" property behaves like this, when it has "Auto" value?
body: <p>Good afternoon!</p>
  
  <p>I hate to bother you guys, but I have little question about the window "height" property in WPF, when it has "Auto" value. Because I want to understand how the things work here. Here is the XAML code:</p>
  
  <pre><code>&lt;Window x:Class="WpfTest.MainWindow"
          x:Name="window"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="Collapsed and Hidden buttons comparison" Width="500"&gt;
      &lt;Grid&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition/&gt;
              &lt;ColumnDefinition/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;StackPanel Height="50" Grid.Column="0" Margin="5,0"&gt;
              &lt;Button Visibility="Collapsed"&gt;This is collapsed button&lt;/Button&gt;
              &lt;Button &gt;Below collapsed button&lt;/Button&gt;
          &lt;/StackPanel&gt;
          &lt;StackPanel Height="50" Grid.Column="1" Margin="5,0"&gt;
              &lt;Button  Visibility="Hidden"&gt;This is hidden button&lt;/Button&gt;
              &lt;Button &gt;Below hidden button&lt;/Button&gt;
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>When I use explicit height like:</p>
  
  <pre><code>Height="300"
  </code></pre>
  
  <p>or </p>
  
  <pre><code> SizeToContent="WidthAndHeight"
  </code></pre>
  
  <p>before width everything is perfect, but when I don't type or delete default height, the window has this strange appearance.</p>
  
  <p><img src="https://i.stack.imgur.com/smd69.jpg" alt="enter image description here"></p>
  
  <p>In the properties "Height" has value "Auto". And when I use procedural code to get the actualHeight it is 526.</p>
  
  <pre><code>MessageBox.Show(Convert.ToString(window.Height),"Height of the window");
  </code></pre>
  
  <p>Can somebody explain please why window behave like this (I mean from where it takes its Height). Thanks in advance.</p>