I would recommend using IValueConverter ; if the original value is not empty or empty, then pass it to a TextBlock. If the original value is null or empty, then visualize the selected text.
public class NullValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string str = (string)value; if (str.IsNullOrWhitespace()) { return "No Data"; } return str; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { ...
However, I just realized that you also want to set the style ... hmmm, possibly a DataTrigger , which sets the style if I need the value "No data",
<TextBlock Text="{Binding Path=SomeProperty, Converter={StaticResource keyToNullValueConverter}"> <TextBlock.Triggers> <DataTrigger Binding="{Binding Path=Text}" Value="No Data"> <Setter Property="FontStyle" Value="Italic"/> </DataTrigger> </TextBlock.Triggers> </TextBlock>
Something like these lines might work.
James webster
source share