Return to Snippet

Revision: 32811
at October 2, 2010 11:11 by jacob4u2


Initial Code
using System.Windows.Data;
public abstract class BaseValueConverter<TFrom> : IValueConverter
{
    protected abstract object DoConversion(TFrom toConvert, object parameter);       

    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (!(value is TFrom))
            return DependencyProperty.UnsetValue;

        return DoConversion((TFrom)value, parameter);
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}

Initial URL
http://jacob4u2.blogspot.com

Initial Description
A base class for very simple value converters in WPF, Windows Phone 7 and Silverlight.

Initial Title
WPF / Silverlight Abstract Value Converter

Initial Tags
c

Initial Language
C#