Define a value converter:
class EmptyToN_AConverter : IValueConverter
{
public object Convert(
object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
string s = value.ToString();
if (string.IsNullOrEmpty(s)) return "N/A";
return s;
}
public object ConvertBack(
object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Example XAML:
<Window.Resources>
...
<local:EmptyToN_AConverter x:Key="NAConverter"/>
</Window.Resources>
...{Binding Path=TheProperty, Converter={StaticResource NAConverter}}...
You may even parameterize the converter and expose the "N/A" in XAML:
public object Convert(
object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
string s = value.ToString();
if (string.IsNullOrEmpty(s)) return parameter.ToString();
return s;
}
...{Binding Path=TheProperty,
Converter={StaticResource NAConverter},
ConverterParameter=N/A}...