title: WPF: Grid inside DataGridTemplateColumn not expanding
body: <p>I'm facing two problems with my projet:</p>
  
  <ul>
  <li><strong><code>SpackPanel</code> not expanding the space available inside <code>DataGridTemplateColumn</code></strong></li>
  <li><strong><code>TextBlock</code> not wrapping</strong></li>
  </ul>
  
  <p>I have a <code>DataGrid</code> with three different columns, and I want the one in the middle to use all available space left. Also in that column I have a StackPanel because I need to have two elements inside:</p>
  
  <ul>
  <li>Border with icon inside that just appears depending on <code>Use_Half_Portion</code> value</li>
  <li>TextBlock showing text</li>
  </ul>
  
  <p>Giving background colors to the elements I have noticed that the StackPanel doesn't fill all of the available space left insite the column, and the wrap in the <code>TextBlock</code> is not being respected. Im supposing that the <code>StackPanel</code> is not assuming the MaxWidth of the <code>DataGridTemplateColumn</code> and it's using unlimited space, and because of that the <code>TextBlock</code> assumes that the limit is not being reached to make the text wrap.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;DataGrid  x:Name="ConsumptionList" ItemsSource="{Binding ConsumptionList}"
          AutoGenerateColumns="False" IsReadOnly="True"
          CanUserReorderColumns="False" CanUserResizeColumns="False"
          BorderBrush="{x:Null}" VerticalContentAlignment="Center" CanUserSortColumns="False" HeadersVisibility="Column" Margin="0,0,0,-4" Background="{x:Null}"&gt;
  
      &lt;DataGrid.Resources&gt;
          &lt;Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource foScrollBar.Small}"/&gt;
      &lt;/DataGrid.Resources&gt;
  
      &lt;DataGrid.ColumnHeaderStyle&gt;
          &lt;StaticResource ResourceKey="clientScreenList.Header"/&gt;
      &lt;/DataGrid.ColumnHeaderStyle&gt;
      &lt;DataGrid.RowStyle&gt;
          &lt;StaticResource ResourceKey="clientScreenList.Lines"/&gt;
      &lt;/DataGrid.RowStyle&gt;
      &lt;DataGrid.CellStyle&gt;
          &lt;StaticResource ResourceKey="clientScreenList.Cells"/&gt;
      &lt;/DataGrid.CellStyle&gt;
      &lt;DataGrid.Style&gt;
          &lt;StaticResource ResourceKey="foBillingList"/&gt;
      &lt;/DataGrid.Style&gt;
  
      &lt;DataGrid.Columns&gt;
          &lt;!--quantity--&gt;
          &lt;DataGridTextColumn x:Name="ConsQttColumn"  MinWidth="20" Width="Auto" MaxWidth="80"  FontFamily="Segoe UI Semibold"
              Binding="{Binding Quantity, Converter={StaticResource DecimalToQuantityConverter}}" Header="{x:Static localization:LanguageRes.consList_quantity}"  /&gt;
          &lt;!--description--&gt;
          &lt;DataGridTemplateColumn x:Name="ConsDescriptionColumn" Header="Descrição" Width="*" &gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Background="#FFDC1A1A"&gt;
                          &lt;Border CornerRadius="30" Grid.Column="0" Width="30" Height="30" Background="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,3,0"&gt;
                              &lt;Border.Style&gt;
                              &lt;Style TargetType="{x:Type Border}"&gt;
                                  &lt;Setter Property="Visibility" Value="Collapsed" /&gt;
                                  &lt;Style.Triggers&gt;
                                      &lt;DataTrigger Binding="{Binding Use_Half_Portion}" Value="1"&gt;
                                          &lt;Setter Property="Visibility" Value="Visible" /&gt;
                                      &lt;/DataTrigger&gt;
                                  &lt;/Style.Triggers&gt;
                              &lt;/Style&gt;
                              &lt;/Border.Style&gt;
                              &lt;TextBlock Grid.Column="1" TextWrapping="Wrap" HorizontalAlignment="Center" Style="{StaticResource icon}" TextAlignment="Center" FontSize="22" Text="{x:Static TechUI:AppConstants+ICONS.HalfDose}" Padding="0" 
                                      Margin="0" Foreground="Black" Background="{x:Null}" /&gt;
                          &lt;/Border&gt;
                          &lt;TextBlock Text="{Binding Product_Description}" HorizontalAlignment="Left" TextAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe UI Semibold" Background="#FFB4AD1C" /&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
          &lt;!-- total price--&gt;
          &lt;DataGridTemplateColumn x:Name="ConsTotalColumn" Header="Preço Total" Width="Auto" MaxWidth="135"&gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Left"  MaxWidth="135" VerticalAlignment="Center" &gt;
                          &lt;TextBlock MaxWidth="135" HorizontalAlignment="Stretch" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe UI Semibold" &gt;
                              &lt;TextBlock.Style&gt;
                                  &lt;Style TargetType="{x:Type TextBlock}"&gt;
                                      &lt;Setter Property="Text" Value="{Binding Total_W_Vat, Converter={StaticResource DecimalToPriceConverter}}" /&gt;
                                          &lt;Style.Triggers&gt;
                                              &lt;DataTrigger Binding="{Binding Is_Composite}" Value="1"&gt;
                                                  &lt;Setter Property="Text" Value=" " /&gt;
                                              &lt;/DataTrigger&gt;
                                          &lt;/Style.Triggers&gt;
                                  &lt;/Style&gt;
                              &lt;/TextBlock.Style&gt;
                          &lt;/TextBlock&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/OZ9Sg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OZ9Sg.jpg" alt="enter image description here"></a></p>
  
  <p>As you can see in the image, the red element is the <code>StackPanel</code> and the green element is the <code>TextBlock</code>. In the first line you can see that the text is being cut and not being wrapped, the full text is "Almondegas Frango"</p>