VisibilityConverter.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Data;
  6. using System.Windows;
  7. namespace Aitex.UI.RecipeEditor
  8. {
  9. public class BoolToVisibilityConverter : IValueConverter
  10. {
  11. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  12. {
  13. if (value == null) return Visibility.Collapsed;
  14. return ((bool)value) ? Visibility.Visible:Visibility.Collapsed;
  15. }
  16. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  17. {
  18. if (value == null) return null;
  19. return object.Equals(value, parameter);
  20. }
  21. }
  22. public class BoolToUnVisibilityConverter : IValueConverter
  23. {
  24. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  25. {
  26. if (value == null) return Visibility.Collapsed;
  27. return ((bool)value) ? Visibility.Collapsed : Visibility.Visible;
  28. }
  29. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  30. {
  31. if (value == null) return null;
  32. return object.Equals(value, parameter);
  33. }
  34. }
  35. class VisibilityConverter : IValueConverter
  36. {
  37. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  38. {
  39. try
  40. {
  41. SmartCellData cellData = value as SmartCellData;
  42. if (cellData == null) return Visibility.Collapsed;
  43. CellType cellType = cellData.RecipeVariableDefine.CellType;
  44. bool isMasked = cellData.IsMasked;
  45. string controlName = (string)parameter;
  46. if (
  47. (controlName == "ReadonlyComboBox" && (cellType == CellType.ReadOnlySelection) && !isMasked) ||
  48. (controlName == "EditableComboBox" && (cellType == CellType.EditableSelection) && !isMasked) ||
  49. (controlName == "TextBox" && (cellType == CellType.TextInput) && !isMasked) ||
  50. (controlName == "DecimalUpDown" && (cellType == CellType.NumInput) && !isMasked) ||
  51. (controlName == "CheckBox" && (cellType == CellType.CheckBox) && !isMasked) ||
  52. (controlName == "EndPoint" && (cellType == CellType.EndPointSetting) && !isMasked) ||
  53. (controlName == "TextBlock" && (cellType == CellType.ReadOnly || isMasked) && (cellType!=CellType.EndPointSetting)) ||
  54. (controlName == "TimePicker" && (cellType == CellType.TimeInput) && !isMasked))
  55. return Visibility.Visible;
  56. return Visibility.Collapsed;
  57. }
  58. catch (Exception ex)
  59. {
  60. System.Diagnostics.Debug.WriteLine(ex.Message);
  61. }
  62. return Visibility.Collapsed;
  63. }
  64. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  65. {
  66. return Visibility.Collapsed;
  67. }
  68. }
  69. }