title: Fit a Textbox and a button in DataGrid Cell
body: <p>I am trying to fit <code>Textblock</code> and a button in <code>DataGrid</code> Cell. The <code>Textblock</code> holds a portion of my text and when I click the button a dialog is display. I general my code looks like the one below </p>
  
  <pre><code>&lt;DataGridTemplateColumn Header="Message" Width="Auto" MinWidth="60"&gt;
      &lt;DataGridTemplateColumn.CellTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel Orientetion="Horrizontal"&gt;
                  &lt;TextBlock MinWidth="200" TextTrimming="CharacterEllipsis" Text="{Binding Text}" /&gt;
                  &lt;Button DockPanel.Dock="Right" Width="90" Margin="1" /&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/DataGridTemplateColumn.CellTemplate&gt;
  &lt;/DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>I want the Button to be always at righter side of the cell and its width to be fixed. The <code>TextBlock</code> needs to be variable, for example when I resize the window, and so the <code>DataGrid</code>, the <code>TextBlock</code> should stretch also.</p>
  
  <p><a href="https://i.stack.imgur.com/kYY36.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kYY36.png" alt="enter image description here"></a></p>
  
  <p>The problem is that, I can not achieve this behaviour / view. The <code>TextBlock</code> varies on each <code>DataGrid</code> line and in some case the button is not at the righter of the cell.</p>
  
  <p><a href="https://i.stack.imgur.com/ab8nk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ab8nk.png" alt="enter image description here"></a></p>
  
  <p>I tried to change the <code>StackPanel</code> to <code>Grid</code> or <code>DockPanel</code> but still I can not get the desirable result.</p>
  
  <p>Using <code>Grid</code></p>
  
  <pre><code>&lt;Grid&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition MinWidth="100" Width="*" /&gt;
          &lt;ColumnDefinition Width="Auto" /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  
      &lt;TextBlock Grid.Column="0" TextTrimming="CharacterEllipsis" Text="{Binding Text}" /&gt;
      &lt;Button Grid.Column="1" Margin="1" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Any thoughts to share?</p>