Reputation: 3281
I have the following multi-binding for my 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. How do I accomplish this ?
Upvotes: 0
Views: 275
Reputation: 63337
You can use the special value of Binding
called 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;
}
Upvotes: 1