I am trying to change a column's Foreground color according to its value. When I try to set the Foreground statically it works but when I use binding with a converter nothing happens.
Here is a small example
<DataGrid Foreground="White" FontSize="13" x:Name="datagrid_results" AutoGenerateColumns="False" ItemsSource="{Binding DataGridTable, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="3,5,1.6,35" MaxHeight="260">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Width="*" Header="Minimum" Binding="{Binding Minimum, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn IsReadOnly="True" Width="*" Header="Maximum" Binding="{Binding Maximum, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn IsReadOnly="True" Width="100" Header="Pass-Fail" Binding="{Binding Pass_Fail, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="{Binding Pass_Fail , Converter={StaticResource s2b}}" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
This is my Converter:
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
Brush myBrush = Brushes.White;
string input = value as string;
switch (input)
{
case "Pass":
myBrush = Brushes.LightGreen;
break;
case "Fail":
myBrush = Brushes.Red;
break;
default:
myBrush = Brushes.White;
break;
}
return myBrush;
}
The weird thing is that when debugging this converter, the brush is returning the correct value. It's just the the cell is not changing its text color. However when I used this:<Setter Property="Foreground" Value="Red" /> my cells change their text color. Is there anything that I might be missing?


Remove Mode=TwoWay from your datagrid first line of xaml