简体   繁体   English

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

[英]How to keep the original value unchanged in MultiBinding

I have the following multi-binding for my TextBlock 我的TextBlock具有以下多重绑定

<Multibinding Converter="{StaticResource myconv}">
 <Binding Path="Property1" />
 <Binding Path="Property2" />
 <Binding Path="Property3" />
</Multibinding>

Here is my converter code 这是我的转换器代码

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

Problem Now what I would like to do here is when all of the Property1 , Property2 and Property3 are null, I want TextBlock to retain its original value. 问题现在我想在这里做的是当所有Property1Property2Property3为空时,我希望TextBlock保留其原始值。 How do I accomplish this ? 我该如何完成?

You can use the special value of Binding called Binding.DoNothing : 您可以使用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