title: WPF DataGridCell Margin
body: <p>I have the following data grid:</p>
  
  <pre><code>&lt;DataGrid Name="PropertiesDataGrid" 
            ItemsSource="{Binding PropertiesDataView, UpdateSourceTrigger=PropertyChanged}"
            SelectedItem="{Binding SelectedProperty, Mode=TwoWay, 
                         UpdateSourceTrigger=PropertyChanged}"
            AutoGenerateColumns="False"
            CanUserAddRows="False"
            MaxHeight="200"&gt;
      &lt;i:Interaction.Behaviors&gt;
          &lt;helper:ScrollIntoViewBehavior/&gt;
      &lt;/i:Interaction.Behaviors&gt;
  
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTemplateColumn Header=""&gt;
              &lt;DataGridTemplateColumn.CellTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Button Command="Delete"
                              Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"&gt;
                          &lt;Image Source="../Resources/red_x.ico" 
                                 Height="15" /&gt;
                      &lt;/Button&gt;
                  &lt;/DataTemplate&gt;
              &lt;/DataGridTemplateColumn.CellTemplate&gt;
          &lt;/DataGridTemplateColumn&gt;
  
          &lt;DataGridTextColumn Header="ID"
                              Width="50" 
                              Binding="{Binding ID}" 
                              ElementStyle="{StaticResource CenterTextCellStyle}" 
                              IsReadOnly="True" /&gt;
  
          &lt;DataGridTextColumn Header="PropertyName"
                              Width="*" 
                              Binding="{Binding PropertyName}" 
                              ElementStyle="{StaticResource LeftTextCellStyle}" /&gt;
  
          &lt;DataGridTextColumn Header="PropertyValue" 
                              Width="300" 
                              Binding="{Binding PropertyValue}" 
                              ElementStyle="{StaticResource LeftTextCellStyle}" /&gt;
      &lt;/DataGrid.Columns&gt;
  
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>Applied to this data grid is the following style:</p>
  
  <pre><code>&lt;Style TargetType="{x:Type DataGridCell}"&gt;
      &lt;Setter Property="Height" Value="22" /&gt;
      &lt;Setter Property="Margin" Value="5,0,0,0" /&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type DataGridCell}"&gt;
                  &lt;Grid Background="{TemplateBinding Background}"&gt;
                      &lt;ContentPresenter VerticalAlignment="Center" /&gt;
                  &lt;/Grid&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>This style adds 5 pixels of spacing to the left of the cell contents and centers the text vertically.</p>
  
  <p>I would like to set the margin of just the first column's cells (<code>&lt;DataGridTemplateColumn Header=""&gt;</code>) to 0.  How can I set this in the DataTemplate.  I know the Margin has to be set on DataGridCell (found by using Snoops) but do not know how to implement in the <code>&lt;DataGridTemplateColumn.CellTemplate&gt;</code></p>