NumConverter.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Data;
  6. namespace Aitex.UI.RecipeEditor
  7. {
  8. public class NumConverter :IValueConverter
  9. {
  10. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  11. {
  12. try
  13. {
  14. string s = (string)value;
  15. decimal d;
  16. if (!decimal.TryParse(s, out d)) return 0;
  17. return d;
  18. }
  19. catch (Exception ex)
  20. {
  21. System.Diagnostics.Debug.WriteLine(ex.Message);
  22. }
  23. return 0;
  24. }
  25. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  26. {
  27. try
  28. {
  29. return value.ToString();
  30. }
  31. catch (Exception ex)
  32. {
  33. System.Diagnostics.Debug.WriteLine(ex.Message);
  34. }
  35. return "0";
  36. }
  37. }
  38. }