I have a PriorityBinding
<PriorityBinding FallbackValue="Bindings were null">
<Binding Path="Foo" />
<Binding Path="Bar" />
</PriorityBinding>
I'd like to make it so if Foo is null it will use Bar and if both are null it will use the FallbackValue. However null is a valid value for this property because it only expects an object.
Is there any way to make the PriorityBinding advance to the next binding when the value is null? I'd prefer to do it in XAML, but if I can't I'll just make a converter for it.
Edit
I ended up just writing a converter for it
public class NullToDependencyPropertyUnsetConverter
: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value ?? Depende开发者_StackOverflow中文版ncyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
I'd go with the valueconverter returning UnsetValue if the bound value is null.
PriorityBindings are more useful if you want to share a datatemplate between different types of objects.
精彩评论