终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ToastIconConverter.cs 2.2 KiB

2 년 전
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using BPASmartClient.CustomResource.UserControls.Enum;
  2. using MahApps.Metro.IconPacks;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. namespace BPASmartClient.CustomResource.Converters
  13. {
  14. public class ToastIconConverter : IMultiValueConverter
  15. {
  16. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  17. {
  18. object value = values[0];
  19. object grid = values[1];
  20. object txt = values[2];
  21. Grid _grid = grid as Grid;
  22. TextBlock _txt = txt as TextBlock;
  23. void WithoutIcon()
  24. {
  25. if (_grid != null)
  26. {
  27. _grid.ColumnDefinitions.RemoveAt(0);
  28. }
  29. if (_txt != null)
  30. {
  31. _txt.HorizontalAlignment = HorizontalAlignment.Center;
  32. }
  33. }
  34. if (value == null)
  35. {
  36. WithoutIcon();
  37. return PackIconFontAwesomeKind.None;
  38. }
  39. ToastIcons _value;
  40. try
  41. {
  42. _value = (ToastIcons)value;
  43. }
  44. catch
  45. {
  46. WithoutIcon();
  47. return PackIconFontAwesomeKind.None;
  48. }
  49. switch (_value)
  50. {
  51. case ToastIcons.Information:
  52. return PackIconFontAwesomeKind.CheckCircleSolid;
  53. case ToastIcons.Error:
  54. return PackIconFontAwesomeKind.TimesSolid;
  55. case ToastIcons.Warning:
  56. return PackIconFontAwesomeKind.ExclamationSolid;
  57. case ToastIcons.Busy:
  58. return PackIconFontAwesomeKind.ClockSolid;
  59. }
  60. WithoutIcon();
  61. return PackIconFontAwesomeKind.None;
  62. }
  63. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  64. {
  65. throw new NotImplementedException();
  66. }
  67. }
  68. }