Does anybody know why I can't use a Binding combined with a ValueConverter? My code works when in the case where I want to specify a Brush. But when I change it to a Color (for instance a GradientStop or the color of a SolidColorBrush) it breaks.
Try the following code its the most basic example I could come up with...
Create a basic user control. Set the Grid.Background to
Color
="{Binding Converter={StaticResource ColorConverter},Source={StaticResource ThemeName}}"
of course you need to create the ColorConverter and ThemeName (just define it as a string anything will do).
Here is the most basic ColorConverter class...
public class ColorConverter: IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Colors.Red;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}