WPF / Silverlight Abstract Value Converter


/ Published in: C#
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. using System.Windows.Data;
  2. public abstract class BaseValueConverter<TFrom> : IValueConverter
  3. {
  4. protected abstract object DoConversion(TFrom toConvert, object parameter);
  5.  
  6. #region IValueConverter Members
  7.  
  8. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  9. {
  10. if (!(value is TFrom))
  11. return DependencyProperty.UnsetValue;
  12.  
  13. return DoConversion((TFrom)value, parameter);
  14. }
  15.  
  16. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  17. {
  18. throw new NotImplementedException();
  19. }
  20.  
  21. #endregion
  22. }

URL: http://jacob4u2.blogspot.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.