Posted By

jacob4u2 on 10/02/10


Tagged

c WPF Silverlight


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


WPF / Silverlight Abstract Value Converter


 / Published in: C#
 

URL: http://jacob4u2.blogspot.com

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

  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. }

Report this snippet  

You need to login to post a comment.