在过去的一年左右时间里,我看到了许多不同的值转换器,用于许多不同的目的,来自许多不同的作者。有一件事情让我印象深刻,那就是它们返回的“默认”值的差异非常大。例如:
public class MyConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// OK, we test for some undesirable, unconvertable situation, typically null...
if (value == null)
{
// And here are a variety of 'defaults' that I have seen, these begin the most typical.
return null;
return DependencyProperty.UnsetValue;
return Binding.DoNothing;
}
//...... other code.. whatever...
}}
那么我的问题是,是否有一种“标准”方法来指示输入值无法转换?
DependencyProperty.UnsetValue
和Binding.DoNothing
之间的实际差别是什么?文档在这里并不是非常清楚。在这两种情况下,绑定引擎的行为有何不同? - bitbonkBinding.DoNothing
会使绑定引擎立即停止,而DependencyProperty.UnsetValue
则告诉绑定引擎使用 FallbackValue。 - myermian