我有一个PriorityBinding
<PriorityBinding FallbackValue="Bindings were null">
<Binding Path="Foo" />
<Binding Path="Bar" />
</PriorityBinding>
Run Code Online (Sandbox Code Playgroud)
我想这样做,如果Foo为null,它将使用Bar,如果两者都为null,它将使用FallbackValue.但是null是此属性的有效值,因为它只需要一个对象.
当值为null时,有没有办法让PriorityBinding前进到下一个绑定?我宁愿在XAML中这样做,但如果我不能,我只会为它做一个转换器.
编辑
我最后只为它写了一个转换器
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();
}
}
Run Code Online (Sandbox Code Playgroud)