Click here to Skip to main content
12,693,082 members (31,808 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked

WPF Simple Data Converter Example

, 3 Oct 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple data converter example in WPF


In this tip, I would like to share the code that I have written for converting numeric value to its words format. It is a very simple prototype and can be extended to be used as a full fledged application or user control.

In this example, I have a list of numbers which is to be populated in combo box. At the time of displaying numbers in combo box, they should be shown in words. For example, 1 -> one, 2 -> two …..

For this purpose, I have created a Data Converter inherited from IValueConveter interface provided by the WPF library.

public class DataConverter : IValueConverter 

Whenever any class is implementing IValueConverter, it needs to implement two methods provided by interface:

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

In Convert method, I have written the logic to convert numeric value into words and return the string.

Coming to the UI side, the window contains just a combo box to be populated with list using data context (binding). The list contains all the numbers, hence we need to put converter to convert numeric values to words.

 ItemsSource="{Binding list,  
 Converter={StaticResource DataConverter}}">

Finally the application looks like:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Suriya A
Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Nayan Soni21-Aug-15 9:32
memberNayan Soni21-Aug-15 9:32 
GeneralMy vote of 1 Pin
kurikv7-Oct-13 3:17
memberkurikv7-Oct-13 3:17 
GeneralMy vote of 1 Pin
Athari4-Oct-13 2:07
professionalAthari4-Oct-13 2:07 
GeneralMy vote of 1 Pin
CzimerA4-Oct-13 2:01
memberCzimerA4-Oct-13 2:01 
GeneralMy vote of 2 Pin
Member 102537903-Oct-13 20:33
memberMember 102537903-Oct-13 20:33 
GeneralRe: My vote of 2 Pin
Suriya A3-Oct-13 20:40
memberSuriya A3-Oct-13 20:40 
GeneralGood start for beginers Pin
Member 24345982-Oct-13 21:23
memberMember 24345982-Oct-13 21:23 
GeneralMy vote of 1 Pin
Daedalus16322-Oct-13 12:41
memberDaedalus16322-Oct-13 12:41 
GeneralRe: My vote of 1 Pin
Suriya A2-Oct-13 19:38
memberSuriya A2-Oct-13 19:38 
QuestionMy vote 4 Pin
Rahat Yasir2-Oct-13 10:19
memberRahat Yasir2-Oct-13 10:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 4 Oct 2013
Article Copyright 2013 by Suriya A
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid