...">

How can I make a PriorityBinding error if the return value is Null?

I have a PriorityBinding

<PriorityBinding FallbackValue="Bindings were null"> <Binding Path="Foo" /> <Binding Path="Bar" /> </PriorityBinding> 

I would like to do so if Foo is null, it will use Bar, and if both are null, then it will use FallbackValue. However, null is a valid value for this property, since it expects only an object.

Is there a way to do a PriorityBinding to go to the next binding when the value is null? I would rather do it in XAML, but if I can’t, I just make a converter for it.

Edit

In the end, I just wrote a converter for it

 public class NullToDependencyPropertyUnsetConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value ?? DependencyProperty.UnsetValue; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } 
+6
wpf
source share
1 answer

I would go with a valueconverter returning UnsetValue if the associated value is null.

PriorityBindings are more useful if you want to share a data sheet between different types of objects.

+5
source share

All Articles