First things first, the
Foreground[
^]
Dependency Property[
^] of the of any
WPF Control[
^] is expecting a
Brush[
^].
Armed with this knowledge, we can now look at your Converter:
public object Convert(object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
var temp = (int)value;
if (temp <100 && temp>50)
{
return "#ff23d3";
}
if(temp>200)
return "da2367";
return new SolidBrush(Colors.Green);
}
1.
"#ff23d3"
= string hex color value (not color object),
not a Brush of any kind.
2.
"da2367"
is a string. Not the same as the first, but still
not a Brush.
3.
new SolidBrush(Colors.Green)
- This is a Solid Color
Brush. This will work.
So, to fix, you need to convert a color value to a
Color class[
^] that can be used with a Brush:
using System.Windows.Media;
Color color = (Color)ColorConverter.ConvertFromString("#FFFF23D3");
Now that you have a Color object you can apply it to a
SolidColorBrush[
^]:
return new SolidBrush(color);
So, your fixed Converter will look like:
public object Convert(object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
var temp = (int)value;
if (temp <100 && temp>50)
return new SolidColorBrush(
(Color)ColorConverter
.ConvertFromString("#FFFF23D3"));
if(temp>200)
return new SolidColorBrush(
(Color)ColorConverter
.ConvertFromString("#FFDA2367"));
return new SolidColorBrush(Colors.Green);
}