Converters can change data from one type to another, translate data based on cultural information, or modify other aspects of the presentation. For examples of some typical converter scenarios, see “Data Conversion” in Data Binding Overview.
The IValueConverter interface and then implement the Convert and ConvertBack methods.
Convert : Modifies the source data before passing it to the target for display in the UI.
ConvertBack : Modifies the target data before passing it to the source object. This method is called only in TwoWay bindings.

Getting Started
Download Source code:=>ConverterTestApplication.rar

You need to have Silverlight 3.0 or 4.0 framework installed on your PC for implementation of converter.
We can create Sliverlight application for Converter.

1.  Create a new Silverlight application. Open Visual Studio 2010 > File > New Project > Select the language (C# or VB.NET) > Select ‘Silverlight’ in the Project Types > from the templates, select Silverlight Application from the installed templates and enter a name for the application
2.   On clicking OK, Let’s structure our project as below

3. First create the Model “Test”

namespace ConverterTestApplication.Model
public class Test
private string _StrLen;
public string StrLen
return _StrLen;
_StrLen = value;

4. We need the IValueConverter, which will be able to convert the string length and return password Strength code like this

using System;

using System.Globalization;

using System.Windows;

using System.Windows.Data;

namespace ConverterTestApplication.Converter


public class Converter12 : IValueConverter


#region IValueConverter Members

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)


string str = value.ToString();

string message = "";

int len = str.Length;

if (len > 0 && len 4 && len 8 && len 12)


message = "strong";


return message;


public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)


return null;





5. In the view, we need to include the xmlns namespace for the ViewModel and the Converter. Create the StaticResource of MainViewModel and testConverter, as shown below and set the DataContext of the LayoutRoot Grid to the MainViewModel.

6. Here is the full code of the XAML page i.e. View:

<UserControl x:Class="ConverterTestApplication.MainPage"








d:DesignHeight="300" d:DesignWidth="400">


<viewModels:Test x:Key="mainViewModel"/>

<converter:Converter12 x:Key="testConverter"/>


<Grid x:Name="LayoutRoot" Background="White"  DataContext="{StaticResource mainViewModel}">


<RowDefinition Height="auto"/>

<RowDefinition Height="auto"/>

<RowDefinition Height="auto"/>

<RowDefinition Height="244*" />



<ColumnDefinition Width="auto"/>

<ColumnDefinition Width="auto"/>

<ColumnDefinition Width="auto"/>

<ColumnDefinition Width="93*" />


<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">Converter Demo Application(Check Password Strength)</TextBlock>

<TextBlock Grid.Row="1" Grid.Column="0">Password</TextBlock>

<TextBox x:Name="txtStr" Width="100" Grid.Row="1" Grid.Column="1" Text="{Binding StrLen,Mode=TwoWay}"  />

<TextBlock Grid.Row="2" Grid.Column="0">Strength :</TextBlock>

<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Text,Converter={StaticResource testConverter},ElementName=txtStr}"/>



Referral Link :=>

No comments

Leave a Reply

− 7 = 1