選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

62 行
2.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Data;
  9. namespace BPA.UIControl.Converters
  10. {
  11. /// <summary>
  12. /// enum => Visiblity
  13. /// </summary>
  14. public class EnumToVisibilityConverter : IValueConverter
  15. {
  16. /// <summary>
  17. /// true 对应 Visibility
  18. /// </summary>
  19. public Visibility TrueVisibility { get; set; }
  20. /// <summary>
  21. /// false 对应 Visibility
  22. /// </summary>
  23. public Visibility FalseVisibility { get; set; }
  24. /// <summary>
  25. /// Initializes a new instance of the <see cref="EnumToVisibilityConverter"/> class.
  26. /// </summary>
  27. public EnumToVisibilityConverter()
  28. {
  29. TrueVisibility = Visibility.Visible;
  30. FalseVisibility = Visibility.Collapsed;
  31. }
  32. /// <inheritdoc/>
  33. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  34. {
  35. return EnumToVisibilityConverter.ConvertEnumToVisibility(value, parameter, TrueVisibility, FalseVisibility);
  36. }
  37. /// <summary>
  38. /// Converts the enum to visibility.
  39. /// </summary>
  40. /// <param name="value">The value.</param>
  41. /// <param name="parameter">The parameter.</param>
  42. /// <param name="trueVisibility">The true visibility.</param>
  43. /// <param name="falseVisibility">The false visibility.</param>
  44. /// <returns>An object.</returns>
  45. public static object ConvertEnumToVisibility(object value, object parameter, Visibility trueVisibility, Visibility falseVisibility)
  46. {
  47. bool flag = EnumToBooleanConverter.ConvertEnumToBool(value, parameter);
  48. return BooleanConverter<Visibility>.ConvertBooleanToType(flag, trueVisibility, falseVisibility);
  49. }
  50. /// <inheritdoc/>
  51. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  52. {
  53. throw new NotImplementedException();
  54. }
  55. }
  56. }