title: How to get WPF Window to autosize to content and no more
body: <p>I have a dialog containing 2 TextBlocks, a Progress Bar and a cancel Button.</p>
  
  <p>Here is the XAML:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication4.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:local="clr-namespace:WpfApplication4"
      mc:Ignorable="d"
      Title="MainWindow" Height="Auto" Width="200"&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="Auto"/&gt;
          &lt;RowDefinition Height="Auto"/&gt;
          &lt;RowDefinition Height="Auto"/&gt;
          &lt;RowDefinition Height="Auto"/&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;TextBlock x:Name="txtFirst" Grid.Row="0"  Margin="5" TextWrapping="Wrap"&gt;This is a really really really really long string that wraps&lt;/TextBlock&gt;
      &lt;TextBlock x:Name="txtSecond" Grid.Row="1"  Margin="5" Text="A Shorter string" TextWrapping="Wrap" MaxWidth="200"/&gt;
      &lt;ProgressBar x:Name="prgProgress" Grid.Row="2" Margin="5" Height="20" /&gt;
      &lt;Button x:Name="btnCancel" Grid.Row="3" Margin="5" Height="25" Width="50"/&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>I would like the Window not to have a fixed height but auto adjust its height based on the size of its children and no more, but can’t see a way to do this. At the moment when I don’t assign anything to the Window’s height, it seems to adopt a height that is much bigger that the content.</p>
  
  <p>Not sure why, or where it gets height value from? If I set Windows Height = “Auto” I get the same thing. All the heights for the RowDefinitions are set to “Auto”, which I take to mean ‘set row height to be row child height’.</p>