Concatenation using BindingConverters

http://blogs.intuidev.com/post/2010/04/12/ConcatenateFieldsMultiValueConverter.aspx

Converter class:

public class ConcatenateConverter : IMultiValueConverter     {         #region IMultiValueConverter Members         public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)         {             string delimiter;             StringBuilder sb = new StringBuilder();             if (parameter != null)             {                 //Use the passed delimiter.                 delimiter = parameter.ToString();             }             else             {                 //Use the default delimiter.                 delimiter = ", ";             }             //Concatenate all fields             foreach (object value in values)             {                 if (value != null && value.ToString().Trim().Length > 0)                 {                     if (sb.Length > 0) sb.Append(delimiter);                     sb.Append(value.ToString());                 }             }             return sb.ToString();         }         public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)         {             throw new NotImplementedException();         }         #endregion     }

Xaml Resources:

        <conv:ConcatenateConverter x:Key="Concatenate"/>

 

Xaml Usage:

        <TextBox Name="PlainText" Grid.Row="5" Grid.Column="1">             <TextBox.Text>                 <MultiBinding Converter="{StaticResource Concatenate}" ConverterParameter="">                     <Binding ElementName="URL" Path="Text"/>                     <Binding ElementName="ContentLength" Path="Text"/>                 </MultiBinding>             </TextBox.Text>         </TextBox>
Advertisements

About vijayvepa

I'm a software consultant for Software Specialists Inc. currently working at Philips Respironics, Pittsburgh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: