终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

63 righe
2.0 KiB

  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Data;
  10. namespace BPASmartClient.SCADAControl.Converters
  11. {
  12. [ValueConversion(typeof(bool), typeof(Visibility))]
  13. public class BoolToVisibilityConverter : IValueConverter
  14. {
  15. static BoolToVisibilityConverter()
  16. {
  17. Instance = new BoolToVisibilityConverter();
  18. }
  19. public static BoolToVisibilityConverter Instance
  20. {
  21. get;
  22. private set;
  23. }
  24. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  25. {
  26. return ((bool)value) ? Visibility.Visible : Visibility.Collapsed;
  27. }
  28. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  29. {
  30. throw new NotImplementedException();
  31. }
  32. }
  33. public class JTokenToBoolConverter : IValueConverter
  34. {
  35. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  36. {
  37. if (value == null)
  38. return value;
  39. else
  40. {
  41. Newtonsoft.Json.Linq.JToken mj = (value as Newtonsoft.Json.Linq.JToken);
  42. if (mj.Type == JTokenType.Boolean) return ((bool)mj);
  43. else if (mj.Type == JTokenType.Integer) return ((int)mj);
  44. else if (mj.Type == JTokenType.Float) return ((float)mj);
  45. else if(mj.Type == JTokenType.String) return ((string)mj);
  46. else return mj.ToString();
  47. }
  48. }
  49. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  50. {
  51. Newtonsoft.Json.Linq.JToken jToken = (value as Newtonsoft.Json.Linq.JToken);
  52. return jToken;
  53. }
  54. }
  55. }