I need to display data on a WPF application colored in proportion to the measurement of the item's property value, like on the image below.
My question is how to provide the color/LinearGradientBrush (green-black-red) based on the relative value? Lowest values should return red(dish), middle values black/gray(ish) and highest values greed(ish), as in the image.
I started binding the background color of each panel to the item's value with a converter that can return some individual colors but I'd like to return a full range of possible LinearGradientBrushes based on the relative value.
Public Class ValueToColorConverter
Inherits MarkupExtension
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Dim v As Double = System.Convert.ToDecimal(value)
If v < 0 Then
Return Brushes.Red
ElseIf v < 0.05 Then
Return Brushes.Gray
Else
Return Brushes.Green
End If
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New System.NotImplementedException()
End Function
Public Overrides Function ProvideValue(ByVal serviceProvider As System.IServiceProvider) As Object
Return Me
End Function
End Class