title: How to get a WPF DataGrid cell to right align without making the selectable area on a new row tiny?
body: <p>I'm using a WPF4.0 DataGrid. When double clicking on a cell in a new row everything works fine <strong>unless</strong> I've added a cell style to that column. For example, I have a numeric column where I want the data right aligned so the xaml looks like this</p>
  
  <pre><code>&lt;DataGridTextColumn Binding="{Binding Path=ImpaId}"
                      CellStyle="{StaticResource CellRightAlign}"&gt;
       &lt;DataGridTextColumn.Header&gt;
            &lt;TextBlock  Style="{StaticResource DataGridHeader}"&gt;Impa&lt;/TextBlock&gt;
       &lt;/DataGridTextColumn.Header&gt;
  &lt;/DataGridTextColumn&gt;
  </code></pre>
  
  <p>Where the style in a shared resource is just:</p>
  
  <pre><code>&lt;Style x:Key="CellRightAlign"&gt;
      &lt;Setter Property="Control.HorizontalAlignment"
              Value="Right" /&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>The resulting selectable area on a new row is shown in the image as that small blue area.This is a very small target for the user to hit, and this happens to be the most likely column they will want to start with on a new row.</p>
  
  <p><img src="https://i.stack.imgur.com/f4Px6.png" alt="DataGrid cell with tiny width"></p>
  
  <p>If I remove the CellStyle, the area works as desired but of course I lose the right alignment.</p>
  
  <p><img src="https://i.stack.imgur.com/CeCna.png" alt="DataGrid cell with proper width"></p>
  
  <p>Does anyone know how to achieve both? </p>
  
  <p><strong>Things I tried</strong> </p>
  
  <ol>
  <li>Setting TargetNullValue on the binding to a format with some width.
  This works on existing rows but has no effect on a new row. </li>
  <li>Setting MinWidth on the column, this did not affect the width of the new row selectable
  area.</li>
  </ol>
  
  <p><strong>Thing that worked:</strong></p>
  
  <p>Using the information from the answer by @AngelWPF I was able to change from using CellStyle to using ElementStyle as follows:</p>
  
  <pre><code>&lt;DataGridTextColumn Binding="{Binding Path=ImpaId}"
                      CellStyle="{StaticResource CellRightAlign}"&gt;
  </code></pre>
  
  <p>Became</p>
  
  <pre><code>&lt;DataGridTextColumn Binding="{Binding Path=ImpaId}"
                      ElementStyle="{StaticResource CellRightAlign}"&gt;
  </code></pre>