title: WPF Datagrid right align numeric columns
body: <p>I'm trying to create a style for the DataGrid cells in my application. I thoight that maybe there is a way to right align the numeric cells in DataGrid using a DataTrigger. Is this even possible?</p>
  
  <p>My style for my DataGrid is this:</p>
  
  <pre><code>&lt;Style TargetType="{x:Type DataGrid}"&gt;
      &lt;Setter Property="AlternatingRowBackground"&gt;
          &lt;Setter.Value&gt;
              &lt;SolidColorBrush Color="#CCCCCC" /&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Setter Property="CanUserAddRows" Value="False" /&gt;
      &lt;Setter Property="CanUserDeleteRows" Value="False" /&gt;
      &lt;Setter Property="Background"&gt;
          &lt;Setter.Value&gt;
              &lt;LinearGradientBrush StartPoint="0,0" EndPoint="1,1"&gt;
                  &lt;GradientStop Offset="0" Color="#CCCCCC" /&gt;
                  &lt;GradientStop Offset="1" Color="#FFFFFF" /&gt;
              &lt;/LinearGradientBrush&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Setter Property="RowHeaderWidth" Value="0" /&gt;
      &lt;Setter Property="CellStyle"&gt;
          &lt;Setter.Value&gt;
              &lt;Style TargetType="{x:Type DataGridCell}"&gt;
                  &lt;Style.Triggers&gt;
                      &lt;Trigger Property="IsSelected" Value="True"&gt;
                          &lt;Setter Property="Background"&gt;
                              &lt;Setter.Value&gt;
                                  &lt;SolidColorBrush Color="#7777FF" /&gt;
                              &lt;/Setter.Value&gt;
                          &lt;/Setter&gt;
                      &lt;/Trigger&gt;
                  &lt;/Style.Triggers&gt;
              &lt;/Style&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>I'm thinking of maybe adding some kind of trigger on the CellStyle to detect if the content is numeric (int, double, decimal,...) and style the cell accordingly. Is this possible?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Thinking about this I've tried several things, but it didn't work. I tried using a DataTrigger defined as:</p>
  
  <pre><code>&lt;DataTrigger Binding="{Binding Converter={StaticResource IsNumericConverter}}" Value="True"&gt;
      &lt;Setter Property="HorizontalContentAlignment" Value="Right" /&gt;
  &lt;/DataTrigger&gt;
  </code></pre>
  
  <p>Where <code>IsNumericConverter</code> is:</p>
  
  <pre><code>public class IsNumericConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
      {
          return value is int || (value is decimal || value is double);
      }
  
      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
      {
          return null;
      }
  }
  </code></pre>
  
  <p>But when I set a breakpoint on the converter I get that the value is of the type of the whole row, not each individual cell...</p>