title: Binding DataGridTemplateColumn.Width property to slider
body: <p>I am trying to bind the width of a DataGridTemplateColumn to a slider to adjust the column's width.</p>
  
  <p>When there are other columns so that a horizontal scroll bar is shown, the sizing of the column has no effect. Here is working sample code:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Window.Resources&gt;
          &lt;x:Array x:Key="strings" Type="sys:String" 
              xmlns:sys="clr-namespace:System;assembly=mscorlib"&gt;
              &lt;sys:String&gt;One&lt;/sys:String&gt;
              &lt;sys:String&gt;Two&lt;/sys:String&gt;
          &lt;/x:Array&gt;
      &lt;/Window.Resources&gt;
      &lt;StackPanel&gt;
          &lt;Slider Name="ImgWidth" Minimum="10" Maximum="500" TickFrequency="1" IsSnapToTickEnabled="True" Value="100"&gt;&lt;/Slider&gt;
  
            &lt;DataGrid ItemsSource="{StaticResource strings}" CanUserAddRows="False" CanUserDeleteRows="False" IsSynchronizedWithCurrentItem="True" AutoGenerateColumns="False"&gt;
              &lt;DataGrid.Columns&gt;
                  &lt;DataGridTemplateColumn Header="Image" Width="{Binding ElementName=ImgWidth, Path=Value}" &gt;
                      &lt;DataGridTemplateColumn.CellTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;Border BorderBrush="Red" BorderThickness="5" Height="100" Width="{Binding ElementName=ImgWidth, Path=Value}"&gt;&lt;/Border&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                  &lt;/DataGridTemplateColumn&gt;
  
                  &lt;DataGridTextColumn Header="Something else" Binding="{Binding}"/&gt;
                  &lt;DataGridTextColumn Header="Something else" Binding="{Binding}"/&gt;
                  &lt;DataGridTextColumn Header="Something else" Binding="{Binding}"/&gt;
                  &lt;DataGridTextColumn Header="Something else" Binding="{Binding}"/&gt;
                  &lt;DataGridTextColumn Header="Something else" Binding="{Binding}"/&gt;
                  &lt;DataGridTextColumn Header="Something else" Binding="{Binding}"/&gt;
  
                  &lt;DataGridTemplateColumn Width="*" /&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Resizing of image works when moving the slider, however whether I have set the Width of the first column to auto or to the binding, it does not scale in both directions when I move the slider.
  When the horizontal scrollbar is not visible then increasing the width works but shrinking doesn't. When horizontal scrollbar is shown, resizing the column does not work in any direction.</p>