VisibilityConverter.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 == "EndPoint" && (cellType == CellType.EndPointSetting) && !isMasked) ||
  40. (controlName == "TextBlock" && (cellType == CellType.ReadOnly || isMasked) && (cellType!=CellType.EndPointSetting)) ||
  41. (controlName == "TimePicker" && (cellType == CellType.TimeInput) && !isMasked))
  42. return Visibility.Visible;
  43. return Visibility.Collapsed;
  44. }
  45. catch (Exception ex)
  46. {
  47. System.Diagnostics.Debug.WriteLine(ex.Message);
  48. }
  49. return Visibility.Collapsed;
  50. }
  51. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  52. {
  53. return Visibility.Collapsed;
  54. }
  55. }
  56. }