Showing posts with label Silverlight Converter. Show all posts
Showing posts with label Silverlight Converter. Show all posts

Sunday, June 3, 2012

Converter in Silverlight

Converter in Silverlight are very useful where you want to display data in different format from the same datasource. Like if you want to bind Boolean value from string you can easily write Converter like this.


 public class TextToBoolConverter : IValueConverter
    {   

/*This method is called while UI rendering*/
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool retVal = false;
/*value is binding value */
/*parameter is converterparameter - It allowed us to use a single converter for multiple purpose*/
            string converterParameter = System.Convert.ToString(parameter);
            string bindValue = System.Convert.ToString(value);
            string statusValue = string.Empty;

            return retVal;
        }

Once you are done with converter.
In resources/App.xaml
add this line

where converter is mapped to the namespace of Converter

to use this converter now



Regards,
Vinod