I have a Textblock which Text attribute is binding to a DateTime? type data, and I want to show something when the DateTime? data is null.
The code below works great.<
Since you can't have a binding inside another binding you will need to use a multi-binding.
Something like:
public class NullConverter : IMultiValueConverter
{
#region Implementation of IMultiValueConverter
public object Convert(object[] values, Type targetType,
object parameter, CultureInfo culture)
{
if (values == null || values.Length != 2)
{
return string.Empty;
}
return (values[0] ?? values[1]).ToString();
}
public object[] ConvertBack(object value, Type[] targetTypes,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}