DynamicActionColumn.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 int Width { get; set; }
  23. protected override void Init()
  24. {
  25. base.Init();
  26. Width = 0;
  27. HeaderText = " ";
  28. Filters = null;
  29. FilterRecord = null;
  30. Position = DynamicActionColumnPosition.End;
  31. }
  32. public FrameworkElement? TextToolTip(string text)
  33. {
  34. if (string.IsNullOrWhiteSpace(text))
  35. return null;
  36. var border = new Border
  37. {
  38. BorderBrush = new SolidColorBrush(Colors.Gray),
  39. BorderThickness = new Thickness(0.75),
  40. CornerRadius = new CornerRadius(5),
  41. Background = new SolidColorBrush(Colors.LightYellow),
  42. Padding = new Thickness(5),
  43. Child = new Label { Content = text }
  44. };
  45. return border;
  46. }
  47. public FrameworkElement? ImageToolTip(BitmapImage image)
  48. {
  49. if (image == null)
  50. return null;
  51. var result = new Border
  52. {
  53. Background = new SolidColorBrush(Colors.LightYellow),
  54. BorderBrush = new SolidColorBrush(Colors.Gray),
  55. BorderThickness = new Thickness(0.75)
  56. };
  57. result.Child = new Image { Source = image };
  58. return result;
  59. }
  60. public abstract object Data(CoreRow? row);
  61. }
  62. public class DynamicTextColumn : DynamicActionColumn
  63. {
  64. public Func<CoreRow?, String> Text { get; private set; }
  65. public Alignment Alignment { get; set; }
  66. public DynamicTextColumn(Func<CoreRow?, String?> text, Func<CoreRow?, bool>? action = null)
  67. {
  68. Alignment = Alignment.MiddleCenter;
  69. Text = text;
  70. Action = action;
  71. }
  72. public override object Data(CoreRow? row) => Text?.Invoke(row);
  73. }
  74. public class DynamicImageColumn : DynamicActionColumn
  75. {
  76. public DynamicImageColumn(Func<CoreRow?, BitmapImage?> image, Func<CoreRow?, bool>? action = null)
  77. {
  78. Image = image;
  79. Action = action;
  80. }
  81. public DynamicImageColumn(BitmapImage image, Func<CoreRow?, bool>? action = null)
  82. {
  83. Image = r => image;
  84. Action = action;
  85. }
  86. public Func<CoreRow?, BitmapImage?> Image { get; protected set; }
  87. public bool AllowHeaderClick { get; set; }
  88. protected override void Init()
  89. {
  90. base.Init();
  91. AllowHeaderClick = false;
  92. }
  93. public override object Data(CoreRow? row) => Image?.Invoke(row);
  94. }
  95. }