[英]How to keep the original value unchanged in MultiBinding
我的TextBlock
具有以下多重绑定
<Multibinding Converter="{StaticResource myconv}">
<Binding Path="Property1" />
<Binding Path="Property2" />
<Binding Path="Property3" />
</Multibinding>
这是我的转换器代码
public class PropertiesSelectorConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return values.Where(v => v != null).FirstOrDefault();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
问题现在我想在这里做的是当所有Property1
, Property2
和Property3
为空时,我希望TextBlock
保留其原始值。 我该如何完成?
您可以使用Binding
的特殊值Binding.DoNothing
:
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var value = values.Where(v => v != null).FirstOrDefault();
return value == null ? Binding.DoNothing : value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.