title: DataGridCell style, how to reference the cells value to bind to a converter?
body: <p>I have a converter that takes a decimal value and converts it to a brush (red for negative and black for positive input).  I also created a style that I want to apply to all <code>DataGridTextColumn</code> that will take decimal values.  If I inline the style for each DataGridTextColumn I can simply specify the related property on the Datacontext in the binding expression.  However I don't want to inline the style and simply have it as a resource, that way I can set the CellStyle to the resource.  The problem is I don't know what to put in the Binding of the value for the Foreground property.  I want to be able to bind it to value that the cell to which it's being applied is bound to.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>    &lt;Window.Resources&gt;
          &lt;!-- This converter takes a decimal value and returns a brush --&gt;
          &lt;conv:NumericValueBrushColorConverter x:Key="NumericValueBrushColorConverter"&gt;&lt;/conv:NumericValueBrushColorConverter&gt;
  
          &lt;Style x:Key="CurrencyStyle" TargetType="DataGridCell"&gt;
              &lt;Setter Property="HorizontalAlignment"  Value="Right" /&gt;
              &lt;Setter Property="Foreground"  Value="{Binding WhatGoesHere, Converter={StaticResource NumericValueBrushColorConverter}}"&gt;&lt;/Setter&gt;
          &lt;/Style&gt;
      &lt;/Window.Resources&gt;             
  
  
      &lt;DataGrid ItemsSource="{Binding CashReport}"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Header="Beginning Cash Available" Binding="{Binding BeginningBalance, StringFormat={}{0:C}}" CellStyle="{StaticResource CurrencyStyle}" /&gt;
              &lt;DataGridTextColumn Header="Ending Cash Available" Binding="{Binding EndingBalance, StringFormat={}{0:C}}" CellStyle="{StaticResource CurrencyStyle}" /&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  </code></pre>
  
  <p><strong>Update #1</strong></p>
  
  <p>As per Jefim's suggestion I should attempt to use the ElementStyle as it works directly on the rendered TextBlock as opposed to (CellStyle) the content control (whatever that is) that holds the TextBlock.</p>
  
  <pre><code>    &lt;Style x:Key="CurrencyStyle" TargetType="TextBlock"&gt;
          &lt;Setter Property="HorizontalAlignment"  Value="Right" /&gt;
          &lt;Setter Property="Foreground" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Text, Converter={StaticResource NumericValueBrushColorConverter}}"/&gt;
      &lt;/Style&gt;
  
      &lt;DataGrid ItemsSource="{Binding CashReport}"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Header="Beginning Cash Available" Binding="{Binding BeginningBalance, StringFormat={}{0:C}}" ElementStyle="{StaticResource CurrencyStyle}" /&gt;
              &lt;DataGridTextColumn Header="Ending Cash Available" Binding="{Binding EndingBalance, StringFormat={}{0:C}}" ElementStyle="{StaticResource CurrencyStyle}" /&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt; 
  </code></pre>
  
  <p>This seems to work, however when I track my converter's Convert method it seems to fire about 28 times or so with empty value being passed to the Convert method.  After that all values flow as expected.  When the grid renders everything looks right, there are no empty cells.  What executes my converter the first 20+ times without values?</p>
  
  <p>Update #2
  I believe my current issue is unrelated to the original question so I moved it out to: <a href="https://stackoverflow.com/questions/8433271/ivalueconverter-executes-more-times-than-expected">IValueConverter executes more times than expected</a></p>