I'm probably over-complicating this but I am trying to bind a decimal value using a custom converter to set the Background property of my LightweightCellEditor as follows:
XAML<UserControl.Resources>
<converters:SentimentColorConverter x:Key="SentimentColorConverter"/>
</UserControl.Resources>
...
<dxg:GridColumn.CellStyle>
<Style TargetType="{x:Type dxg:LightweightCellEditor}">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{Binding WeightedAverageSentimentNumeric, Converter={StaticResource SentimentColorConverter}}" />
</Setter.Value>
</Setter>
</Style>
</dxg:GridColumn.CellStyle>
And my converter class:
C#public class SentimentColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is decimal sentimentScore)
{
return sentimentScore switch
{
> 0.5m => Colors.LightGreen,
> 0m => Colors.PaleGreen,
< -0.5m => Colors.LightCoral,
< 0m => Colors.LightPink,
_ => Colors.LightYellow
};
}
return Colors.LightGray; // Default for null or invalid values
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
The background never gets set however. If I set a breakpoint in the Convert() method it never gets triggered. If I set the Background property to a hard-coded Color value, it works as expected so presumably I'm doing something wrong with the binding.
Thanks for your help.