title: WPF - How can I auto-resize DataGrid column to fit contents
body: <p>I have a WPF DataGrid that display some data. Now I want to set auto-resize for some specific columns, not all. Here is my current behavior of DataGrid:</p>
  
  <p><a href="https://i.stack.imgur.com/nB2qy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nB2qy.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/9HDeR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9HDeR.png" alt="enter image description here"></a></p>
  
  <p>This is my expectation (column width should fit its content):</p>
  
  <p><a href="https://i.stack.imgur.com/gylge.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gylge.png" alt="enter image description here"></a></p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>...
  &lt;DataGridTextColumn Binding="{Binding ShippingNumber}" Header="出荷No." ElementStyle="{DynamicResource TextAlignCenter}" IsReadOnly="True"/&gt;
  &lt;DataGridTextColumn Binding="{Binding DivisionDisplay}" Header="区分" ElementStyle="{DynamicResource TextAlignCenter}" IsReadOnly="True"/&gt;
  &lt;DataGridTextColumn Binding="{Binding ShippingDestinationCode}" Header="出荷先コード" ElementStyle="{DynamicResource TextAlignCenter}" IsReadOnly="True"/&gt;
  &lt;DataGridTextColumn Width="Auto" Binding="{Binding ShippingDestinationNameDisplay}" Header="出荷先名" ElementStyle="{DynamicResource TextAlignCenter}" IsReadOnly="True"/&gt;
  &lt;DataGridCheckBoxColumn Binding="{Binding IsCompletedStockOutcomming}" Header="出庫済み" IsReadOnly="True"&gt;
      &lt;DataGridCheckBoxColumn.ElementStyle&gt;
           &lt;Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}"&gt;
                &lt;Setter Property="HorizontalAlignment" Value="Center"/&gt;
                &lt;Setter Property="Margin" Value="0"/&gt;
                &lt;Setter Property="IsHitTestVisible" Value="False"/&gt;
                &lt;Setter Property="Focusable" Value="False"/&gt;
           &lt;/Style&gt;
       &lt;/DataGridCheckBoxColumn.ElementStyle&gt;
  &lt;/DataGridCheckBoxColumn&gt;
  </code></pre>
  
  <p>My project is applying MVVM light pattern so it does not allow to put any code in code-behind, just in ViewModel.
  I also set <code>With="Auto"</code> but still no use. Can anyone help me to make it works? Thanks.</p>