VisibilityConverter.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. class VisibilityConverter : IValueConverter
  23. {
  24. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  25. {
  26. try
  27. {
  28. SmartCellData cellData = value as SmartCellData;
  29. if (cellData == null) return Visibility.Collapsed;
  30. CellType cellType = cellData.RecipeVariableDefine.CellType;
  31. bool isMasked = cellData.IsMasked;
  32. string controlName = (string)parameter;
  33. if (
  34. (controlName == "ReadonlyComboBox" && (cellType == CellType.ReadOnlySelection) && !isMasked) ||
  35. (controlName == "EditableComboBox" && (cellType == CellType.EditableSelection) && !isMasked) ||
  36. (controlName == "TextBox" && (cellType == CellType.TextInput) && !isMasked) ||
  37. (controlName == "DecimalUpDown" && (cellType == CellType.NumInput) && !isMasked) ||
  38. (controlName == "CheckBox" && (cellType == CellType.CheckBox) && !isMasked) ||
  39. (controlName == "TextBlock" && (cellType == CellType.ReadOnly || isMasked)) ||
  40. (controlName == "TimePicker" && (cellType == CellType.TimeInput) && !isMasked))
  41. return Visibility.Visible;
  42. return Visibility.Collapsed;
  43. }
  44. catch (Exception ex)
  45. {
  46. System.Diagnostics.Debug.WriteLine(ex.Message);
  47. }
  48. return Visibility.Collapsed;
  49. }
  50. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  51. {
  52. return Visibility.Collapsed;
  53. }
  54. }
  55. }