Without Converter
<TextBlock.Text> <MultiBinding StringFormat="{}[{0} - {1}]"> <Binding Path="Min" FallbackValue=""/> <Binding Path="Max" FallbackValue=""/> </MultiBinding> </TextBlock.Text> </TextBlock>
Using Converter
public class RangeMultiValueConvertor : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null) return string.Empty; if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue) { return string.Empty; } return (string.Format("[{0} - {1}]", values[0], values[1])); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { return null; } }<local:RangeMultiValueConvertor x:Key="rangeConverter"/>
<TextBlock.Text> <MultiBinding Converter="{StaticResource rangeConverter}"> <Binding Path="Min"/> <Binding Path="Max"/> </MultiBinding> </TextBlock.Text>
This blog is primarily a compilation of frequently faced issues by developers with solutions which I have implemented to solve them
Friday, May 15, 2015
WPF MultiBindng Converter example
Labels:
MultiBindng Converter example,
WPF
Solution Architect employed with Mercedes Benz with about 14 years of experience in Microsoft Technologies.
Subscribe to:
Posts (Atom)