I have a wpf listbox that implements a DataTemplate that contains a TextBlock.
<local:BooleanToFontColorConverter x:Key="boolToFontColor" />
<DataTemplate x:Key="ListBox_DataTemplateSpeakStatus">
<Label Width="Auto">
<TextBlock Foreground="{Binding Path=myProperty, Converter={StaticResource boolToFontColor}}" />
</Label>
</DataTemplate>
My task at hand is upon the changing of "myProperty", I want the color of the font to be different. My converter looks like this:
public class BooleanToFontColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
if (value is Boolean)
{
return ((bool)value) ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);
}
return new SolidColorBrush(Colors.Black);
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
throw new NotImplementedException();
}
}
This works. The font color (foreground) will turn red upon the changing of the bound property.
My question is this: I would like my font to change to being red, AND bold, AND italics. I know that this is possible via using textblock inlines, but is it possible to do all three of these things using my converter?
Thank you to everyone with thoughts and insight that respond.