You can achieve this through a DataTrigger as follows:
<TextBlock> <TextBlock.Style> <Style TargetType="TextBlock"> <Style.Triggers> <DataTrigger Binding="{Binding NewEpisodesAvailable}" Value="True"> <Setter Property="FontWeight" Value="Bold"/> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock>
Or you can use IValueConverter , which converts bool to FontWeight.
public class BoolToFontWeightConverter : DependencyObject, IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return ((bool)value) ? FontWeights.Bold : FontWeights.Normal; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return Binding.DoNothing; } }
XAML:
<TextBlock FontWeight="{Binding IsEnable, Converter={StaticResource BoolToFontWeightConverter}}"/>
Make sure you declare the converter as a resource in XAML.
source share