I am not exactly sure what you mean by an empty cell so I cannot give an exact solution to your less than precise problem statement but you have at least 3 options to explore:
1> Use a FallBack binding option:
You can specify to show a certain data item when the normal data item is not available:
WPF Binding FallbackValue set to Binding - Stack Overflow[
^]
- Either use the
FallbackValue as shown in the question section of the linked page or use the alternative binding via
PriorityBinding
shown in the answer section.
2> Use a converter: You can always use a statndard
IValueConverter
to do essantially the same default value display logic as in 1>. The Difference is that the converter is a C#/VB.Net piece of code that gives you way may options to integrate different and larger scenarios should you see many different cases and want to react to them in a different fashion.
3> An
IMultiValueConverter
gives you most flexibility and options towards binding from multiple sources and converting values into a common format. Here is an example that I just typed out (have not compiled it) - it takes a string and a boolean value (eg IsEnabled) as input and converts it into a string.
[ValueConversion(typeof(string), typeof(string))]
public class ItemTypeDisplayNameToTextConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
return Binding.DoNothing;
if (values.Length != 2)
return Binding.DoNothing;
var item = values[0] as string;
if (item == null)
return Binding.DoNothing;
if (values[1] is bool == false)
return Binding.DoNothing;
bool isEnabled = (bool)values[1];
if (isEnabled == false)
return string.Empty;
if (string.IsNUllOrEmtpy(item))
return string.Empty;
return item;
}
object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
You can download a sample solution, set a breakpoint in the converter, and start the demo if you want to see this working in-situ:
InplaceEditBoxLib/ItemTypeDisplayNameToTextConverter.cs at master · Dirkster99/InplaceEditBoxLib · GitHub[
^]
I hope this helps. Let me know if you were able to solve your problem or if you see a different problem.