终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BoolToVisibilityConverter.cs 2.0 KiB

преди 2 години
преди 2 години
преди 2 години
преди 2 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }