DynamicActionColumn.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Media;
  5. using System.Windows.Media.Imaging;
  6. using InABox.Core;
  7. using Image = System.Windows.Controls.Image;
  8. using Label = System.Windows.Controls.Label;
  9. namespace InABox.DynamicGrid
  10. {
  11. public abstract class DynamicActionColumn : DynamicColumnBase
  12. {
  13. public DynamicActionColumnPosition Position { get; set; }
  14. public Func<CoreRow?, bool>? Action { get; set; }
  15. public Func<DynamicActionColumn, CoreRow?, FrameworkElement?>? ToolTip { get; set; }
  16. public string[] SelectedFilters { get; set; }
  17. public string[] Filters { get; set; }
  18. public Func<CoreRow, string[], bool> FilterRecord { get; set; }
  19. public Func<CoreRow[], ContextMenu> ContextMenu { get; set; }
  20. public object Tag { get; set; }
  21. public string HeaderText { get; set; }
  22. public bool VerticalHeader { get; set; }
  23. public int Width { get; set; }
  24. protected override void Init()
  25. {
  26. base.Init();
  27. Width = 0;
  28. HeaderText = " ";
  29. Filters = null;
  30. FilterRecord = null;
  31. Position = DynamicActionColumnPosition.End;
  32. }
  33. public FrameworkElement? TextToolTip(string text)
  34. {
  35. if (string.IsNullOrWhiteSpace(text))
  36. return null;
  37. var border = new Border
  38. {
  39. BorderBrush = new SolidColorBrush(Colors.Gray),
  40. BorderThickness = new Thickness(0.75),
  41. CornerRadius = new CornerRadius(5),
  42. Background = new SolidColorBrush(Colors.LightYellow),
  43. Padding = new Thickness(5),
  44. Child = new Label { Content = text }
  45. };
  46. return border;
  47. }
  48. public FrameworkElement? ImageToolTip(BitmapImage image)
  49. {
  50. if (image == null)
  51. return null;
  52. var result = new Border
  53. {
  54. Background = new SolidColorBrush(Colors.LightYellow),
  55. BorderBrush = new SolidColorBrush(Colors.Gray),
  56. BorderThickness = new Thickness(0.75)
  57. };
  58. result.Child = new Image { Source = image };
  59. return result;
  60. }
  61. public abstract object Data(CoreRow? row);
  62. }
  63. public class DynamicTextColumn : DynamicActionColumn
  64. {
  65. public Func<CoreRow?, String> Text { get; private set; }
  66. public Alignment Alignment { get; set; }
  67. public DynamicTextColumn(Func<CoreRow?, String?> text, Func<CoreRow?, bool>? action = null)
  68. {
  69. Alignment = Alignment.MiddleCenter;
  70. Text = text;
  71. Action = action;
  72. VerticalHeader = false;
  73. }
  74. public override object Data(CoreRow? row) => Text?.Invoke(row);
  75. }
  76. public class DynamicImageColumn : DynamicActionColumn
  77. {
  78. public DynamicImageColumn(Func<CoreRow?, BitmapImage?> image, Func<CoreRow?, bool>? action = null)
  79. {
  80. Image = image;
  81. Action = action;
  82. VerticalHeader = true;
  83. }
  84. public DynamicImageColumn(BitmapImage image, Func<CoreRow?, bool>? action = null)
  85. {
  86. Image = r => image;
  87. Action = action;
  88. }
  89. public Func<CoreRow?, BitmapImage?> Image { get; protected set; }
  90. public bool AllowHeaderClick { get; set; }
  91. protected override void Init()
  92. {
  93. base.Init();
  94. AllowHeaderClick = false;
  95. }
  96. public override object Data(CoreRow? row) => Image?.Invoke(row);
  97. }
  98. }