繁体   English   中英

如何在MultiBinding中保持原始值不变

[英]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();
    }
}

问题现在我想在这里做的是当所有Property1Property2Property3为空时,我希望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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM