This project is read-only.

ConcatenationConverter

Concatenation converter concatenate a string property of all elements in a collection during data binding using specified separator between each value. The converter can concatenate property of elements within nested collections. Separator and nested levels are specified using a ConcatenationParameter object and passed as ConverterParameter duding binding.

Namespace

StoreAppLib.Converters

Using ConcatenationConverter

To use ConcatenationConverter in your project, add the reference to StoreAppLib project or install StoreAppLib from Visual Studio "Manage NuGet Packages" tool.

To use the converter while binding first declare the converter and concatenation parameter in the App.xaml file.

<Application
   xmlns:storeAppConverter="using:StoreAppLib.Converters"
   ... >
   <Application.Resources>
       <ResourceDictionary>

           <storeAppConverter:ConcatenationConverter
               
x:Key="ConcatenationConverter" />   

           <storeAppConverter:ConcatenationParameter
               
x:Key="LanguageConcatenationParameter" 
                Property
="Employees.Languages.Name" 
                Separator
="," Distinct="True"
/>
   

        </ResourceDictionary>
   </Application.Resources>
</
Application>

The concatenation parameter declaration in the above code can be used to concatenate languages of all employees in all departments. The ConcatenationConverter loop through each employee collection in each department, find the distinct languages and then concatenation them using comma separator.

Following code shows the usage of the converter while binding. 

<TextBlock Text="{Binding Company.Departments,
           Converter
={StaticResource ConcatenationConverter},
           ConverterParameter
={StaticResource LanguageConcatenationParameter}}"
           Style
="{StaticResource BasicTextStyle}" />

Last edited Nov 28, 2012 at 1:43 AM by sureshkumart, version 6

Comments

No comments yet.