In the XAML provided below, I don\'t have the value for Phone sometimes. When that happens, the value is missing, but the TextBlock is still occupying the space
Instead of introducing a style just for this, for this sort of thing I tend to prefer using a converter that will handle a null or empty string.
Where StringToVisibilityConverter is defined like this:
[ValueConversion(typeof(string), typeof(Visibility))]
public class StringToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (string.IsNullOrEmpty((string)value))
{
return Visibility.Collapsed;
}
else
{
return Visibility.Visible;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}