You have two ways to solve this issue:
You can extend your converter by additional properties which will be filled by the binding
public class BooleanToBrushConverter
: IValueConverter
{
public Brush TrueBrush { get; set; }
public Brush FalseBrush { get; set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool)
{
return (bool) value
? TrueBrush
: FalseBrush;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Now you can initialize it by the page resources
<BooleanToBrushConverter x:Key="BooleanToBrushConverter" TrueBrush="{StaticResource PhoneAccentBrush}" FalseColor="{StaticResource PhoneSubtleBrush}" />
And use it as easy as
<TextBlock Foreground="{Binding IsBlue, Converter={StaticResource BooleanToBrushConverter}}" />
The second solution is the fix of your code to recover brushes from the application resources
public class BoolToColorConverter
: IValueConverter{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (value is bool && (bool)value) ? Application.Current.Resources["PhoneAccentBrush"] : Application.Current.Resources["PhoneSubtleBrush"];
}
}