DynamicActionColumn.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. namespace InABox.DynamicGrid
  8. {
  9. public class DynamicActionColumn : DynamicColumnBase
  10. {
  11. public DynamicActionColumn(Func<CoreRow?, BitmapImage?> image, Func<CoreRow?, bool>? action = null)
  12. {
  13. Image = image;
  14. Action = action;
  15. }
  16. public DynamicActionColumn(BitmapImage image, Func<CoreRow?, bool>? action = null)
  17. {
  18. Image = r => image;
  19. Action = action;
  20. }
  21. public Func<CoreRow?, BitmapImage?> Image { get; protected set; }
  22. public Func<CoreRow?, bool>? Action { get; protected set; }
  23. public Func<DynamicActionColumn, CoreRow, FrameworkElement>? ToolTip { get; set; }
  24. public DynamicActionColumnPosition Position { get; set; }
  25. public string[] SelectedFilters { get; set; }
  26. public string[] Filters { get; set; }
  27. public Func<CoreRow, string[], bool> FilterRecord { get; set; }
  28. public bool AllowHeaderClick { get; set; }
  29. public Func<CoreRow[], ContextMenu> ContextMenu { get; set; }
  30. public object Tag { get; set; }
  31. public string HeaderText { get; set; }
  32. public int Width { get; set; }
  33. protected override void Init()
  34. {
  35. base.Init();
  36. Width = 0;
  37. HeaderText = " ";
  38. AllowHeaderClick = false;
  39. Filters = null;
  40. FilterRecord = null;
  41. Position = DynamicActionColumnPosition.End;
  42. }
  43. public FrameworkElement? TextToolTip(string text)
  44. {
  45. if (string.IsNullOrWhiteSpace(text))
  46. return null;
  47. var border = new Border
  48. {
  49. BorderBrush = new SolidColorBrush(Colors.Gray),
  50. BorderThickness = new Thickness(0.75),
  51. CornerRadius = new CornerRadius(5),
  52. Background = new SolidColorBrush(Colors.LightYellow),
  53. Padding = new Thickness(5),
  54. Child = new Label { Content = text }
  55. };
  56. return border;
  57. }
  58. public FrameworkElement? ImageToolTip(BitmapImage image)
  59. {
  60. if (image == null)
  61. return null;
  62. var result = new Border
  63. {
  64. Background = new SolidColorBrush(Colors.LightYellow),
  65. BorderBrush = new SolidColorBrush(Colors.Gray),
  66. BorderThickness = new Thickness(0.75)
  67. };
  68. result.Child = new Image { Source = image };
  69. return result;
  70. }
  71. }
  72. }