title: How can I get checkbox to work in WPF datagrid
body: <p>I am trying to add a checkbox column to my datagrid so that users can easily see what is selected and easily select multiple columns without needing to know how to with the CTRL button. Would someone mind assisting?</p>
  
  <p>The check box will un-check if already selected but I can not get it to become checked when I click it.</p>
  
  <pre><code>&lt;Window.Resources&gt;
          &lt;DataTemplate x:Key="isSelectedCheckBoxColumn"&gt;
                  &lt;CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}}"&gt;
                      &lt;CheckBox.LayoutTransform&gt;
                          &lt;ScaleTransform ScaleX="1.5" ScaleY="1.5" /&gt;
                      &lt;/CheckBox.LayoutTransform&gt;
                  &lt;/CheckBox&gt;
          &lt;/DataTemplate&gt;
          &lt;Style x:Key="RowStyleWithAlternation" TargetType="DataGridRow"&gt;
              &lt;Setter Property="SnapsToDevicePixels" Value="True" /&gt;
              &lt;Setter Property="Background" Value="GhostWhite"/&gt;
              &lt;Setter Property="FontWeight" Value="Normal"/&gt;
              &lt;Setter Property="ContextMenu" Value="{x:Null}"/&gt;
              &lt;Style.Triggers&gt;
                  &lt;Trigger Property="AlternationIndex" Value="1"&gt;
                      &lt;Setter Property="Background" Value="#C1FFC1"/&gt;
                  &lt;/Trigger&gt;
                  &lt;Trigger Property="IsMouseOver" Value="True"&gt;
                      &lt;Setter Property="Background" Value="#F9F99F"/&gt;
                  &lt;/Trigger&gt;
                  &lt;Trigger Property="IsSelected" Value="True"&gt;
                      &lt;Setter Property="Background" Value="LightBlue" /&gt;
                  &lt;/Trigger&gt;
                  &lt;Trigger Property="Validation.HasError" Value="True" &gt;
                      &lt;Setter Property="Effect"&gt;
                          &lt;Setter.Value&gt;
                              &lt;DropShadowEffect Color="Red" ShadowDepth="0" BlurRadius="20" /&gt;
                          &lt;/Setter.Value&gt;
                      &lt;/Setter&gt;
                      &lt;Setter Property="BorderThickness" Value="2" /&gt;
                      &lt;Setter Property="BorderBrush" Value="Red" /&gt;
                      &lt;Setter Property="Foreground" Value="Blue" /&gt;
                      &lt;Setter Property="FontSize" Value="12" /&gt;
                  &lt;/Trigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
  
          &lt;Style x:Key="CenterCellStyle" TargetType="{x:Type DataGridCell}"&gt;
                 &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type DataGridCell}"&gt;
                          &lt;Grid&gt;
                          &lt;ContentPresenter HorizontalAlignment="center"/&gt;
                      &lt;/Grid&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
  
          &lt;Style x:Key="RightCellStyle" TargetType="{x:Type DataGridCell}"&gt;
                 &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type DataGridCell}"&gt;
                          &lt;Grid&gt;
                          &lt;ContentPresenter HorizontalAlignment="Right"/&gt;
                      &lt;/Grid&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
      &lt;/Window.Resources&gt;
  
  
                  &lt;DataGrid Grid.Row="1" AutoGenerateColumns="False" Name="grid_achCredit" RowStyle="{StaticResource RowStyleWithAlternation}" AlternationCount="2" FontSize="15" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="False" SelectionMode="Extended"&gt;
                      &lt;DataGrid.Columns&gt;
                          &lt;DataGridTemplateColumn Header="" CellTemplate="{StaticResource isSelectedCheckBoxColumn}" IsReadOnly="False"/&gt;
                          &lt;DataGridTextColumn Header="ID" Width="Auto"  IsReadOnly="False" Binding="{Binding ID}" /&gt;
                          &lt;DataGridTextColumn Header="TransDate" Width="Auto"  IsReadOnly="False" Binding="{Binding transactionDate, StringFormat=\{0:MM-dd-yyyy\}}" /&gt;
                          &lt;DataGridTextColumn Header="Payor" Width="Auto"  IsReadOnly="False" Binding="{Binding payer}" /&gt;
                          &lt;DataGridTextColumn Header="Description" Width="*"  IsReadOnly="False" Binding="{Binding description}" /&gt;
                          &lt;DataGridTextColumn Header="Amount" Width="Auto"  IsReadOnly="False" Binding="{Binding amount, StringFormat=C}" /&gt;
                          &lt;DataGridTextColumn Header="Balance" Width="Auto"  IsReadOnly="False" Binding="{Binding amount, StringFormat=C}" /&gt;
                          &lt;DataGridTextColumn Header="Selected By" Width="*" IsReadOnly="False" Binding="{Binding lockedUser}"/&gt;
                      &lt;/DataGrid.Columns&gt;
                  &lt;/DataGrid&gt;
  </code></pre>