Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we have both TypeConverters and IValueConverter in WPF?

I am new to WPF. I just don't understand why there is a need for TypeConverters and IValueConverter in WPF. The purpose of both objects is to convert a value to specific type; but why both?

Thanks in advance.

like image 455
Pavan Tiwari Avatar asked Jul 07 '14 09:07

Pavan Tiwari


1 Answers

IValueConverter is used only in data-binding scenarios. It allows you to format values before they are displayed in the UI or to parse values from UI controls so that they can be stored in the binding source. an example would be to convert an IsDirty flag to an "*" in the UI or a Color instance to a Brush instance. from my own experience i've used IValueConverter just for formatting purposes (that is, only implementing the Convert method).

A TypeConverter derived class is mostly used to convert to/from string values. this can be used for setting a property of a custom type in XAML.

like image 156
flo_badea Avatar answered Oct 03 '22 14:10

flo_badea