ToNumberConverter.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Data;
  6. namespace Aitex.Smart.UI.Converters
  7. {
  8. public class ToNumConverter : IValueConverter
  9. {
  10. #region IValueConverter Members
  11. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  12. {
  13. if (value == null) return 0;
  14. double ret;
  15. if (double.TryParse(value.ToString(), out ret))
  16. return ret;
  17. return 0;
  18. }
  19. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  20. {
  21. throw new NotImplementedException();
  22. }
  23. #endregion
  24. }
  25. public class TwoPointNumConverter : IValueConverter
  26. {
  27. #region IValueConverter Members
  28. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  29. {
  30. if (value == null) return "-";
  31. double ret;
  32. if (double.TryParse(value.ToString(), out ret))
  33. return ret.ToString("F1");
  34. return "-";
  35. }
  36. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  37. {
  38. throw new NotImplementedException();
  39. }
  40. #endregion
  41. }
  42. }