Pass Value from Binding to Converter in ElementStyle
I have a DataGrid where I'm setting the ElementStyle on multiple columns. I would like the style to turn the Foreground of the text in the column to red if it is negative. My converter work when I set it on each column and specify the Value, in the example below, 'Imbalance' has the numeric value that is sent to the converter to change it to red if it's negative. Of course every column I 开发者_开发知识库use this style on has a different Binding property (Imbalance, Supply, Scheduled).
How do I use a style in my resources to accomplish this vs. specifying the converter with the property name on every column?
ElementStyle="{StaticResource NomVolumeStyle}"
<Style x:Key="NomVolumeStyle" TargetType="{x:Type TextBlock}">
<Setter Property="TextAlignment" Value="Right" />
<Setter Property="Foreground" Value="{Binding Imbalance, Converter={StaticResource NegativeNumberColorConverter}}" />
</Style>
精彩评论