SliderConver.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Data;
  9. namespace MeterVision.Util
  10. {
  11. public class SliderConvert : IValueConverter
  12. {
  13. //当值从绑定源传播给绑定目标时,调用方法Convert
  14. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  15. {
  16. //if (value == null)
  17. // return DependencyProperty.UnsetValue;
  18. //DateTime date = (DateTime)value;
  19. //return date.ToString("yyyy-MM-dd");
  20. try
  21. {
  22. return System.Convert.ToInt16(value);
  23. }
  24. catch
  25. {
  26. return 100;
  27. }
  28. }
  29. //当值从绑定目标传播给绑定源时,调用此方法ConvertBack
  30. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  31. {
  32. //string str = value as string;
  33. //DateTime txtDate;
  34. //if (DateTime.TryParse(str, out txtDate))
  35. //{
  36. // return txtDate;
  37. //}
  38. //return DependencyProperty.UnsetValue;
  39. return int.Parse(value.ToString());
  40. }
  41. }
  42. }