title: WPF: Order of stretch sizing
body: <p>I'm creating a modal dialog window which contains three essential parts: a TextBlock containing instructions, a ContentControl for the dialog panel, and a ContentControl for the dialog buttons. Each of these parts are contained in a separate Grid row.</p>
  
  <p>I have some specific constraints when it comes to how the dialog should be sized. The issue I'm having is with the instructions TextBlock. I want the instructions to be as wide as the ContentControl for the dialog panel. The instructions should then wrap and grow vertically as needed. Should the instructions not be able to grow vertically, then it should begin to grow horizontally.</p>
  
  <p>Getting the instructions to be the width of the ContentControl and grow vertically was simple. The part I can't seem to figure out is how to get it to grow horizontally when out of vertical space. My initial thought was to create a class that extends TextBlock and override MeasureOverride. However, that method is sealed. Currently, I'm playing with the idea of have the dialog Window override MeasureOverride to calculate the available size for the instructions block.</p>
  
  <p>Am I missing a much simpler way of accomplishing this? Does anyone have any better ideas than this? Messing with MeasureOverride seems like it will be a lot of work.</p>
  
  <p>Here is some sample code to give you a general idea of how the dialog is laid out:</p>
  
  <pre><code>&lt;Window
      x:Class="Dialogs.DialogWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      x:Name="dialogWindow"
      ShowInTaskbar="False"
      WindowStyle="None"
      AllowsTransparency="True"
      Background="Transparent"
      ResizeMode="NoResize"
      SizeToContent="WidthAndHeight"
      WindowStartupLocation="CenterScreen"&gt;
  
      &lt;Border Style="{StaticResource WindowBorderStyle}" Margin="15"&gt;
          &lt;Grid&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height="Auto"/&gt;
                  &lt;RowDefinition Height="Auto"/&gt;
                  &lt;RowDefinition Height="Auto"/&gt;
              &lt;/Grid.RowDefinitions&gt;
  
              &lt;TextBlock
                  Margin="25,5"
                  VerticalAlignment="Top"
                  HorizontalAlignment="Left"
                  Text="{Binding Instructions}"
                  TextWrapping="Wrap"
                  Width="{Binding ElementName=panelContentControl, Path=ActualWidth, Mode=OneWay}"/&gt;
  
              &lt;ContentControl
                  x:Name="panelContentControl"
                  Grid.Row="1"
                  Margin="25,5"
                  Content="{Binding PanelContent}"/&gt;
  
              &lt;ContentControl
                  x:Name="buttonsContentControl"
                  Grid.Row="2"
                  HorizontalAlignment="Right"
                  VerticalAlignment="Center"
                  Margin="25,5"
                  Content="{Binding ButtonsContent}"/&gt;
          &lt;/Grid&gt;
      &lt;/Border&gt;
  
  &lt;/Window&gt;
  </code></pre>