DynamicActionColumn.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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; } = DynamicActionColumnPosition.End;
  14. public delegate bool ActionDelegate(CoreRow? row);
  15. public delegate FrameworkElement? ActionColumnToolTip(DynamicActionColumn column, CoreRow? row);
  16. public ActionDelegate? Action { get; set; }
  17. public ActionColumnToolTip? ToolTip { get; set; }
  18. public string[]? SelectedFilters { get; set; }
  19. public string[]? Filters { get; set; } = null;
  20. public Func<CoreRow, string[], bool>? FilterRecord { get; set; } = null;
  21. public Func<CoreRow[]?, ContextMenu?>? ContextMenu { get; set; }
  22. public string HeaderText { get; set; } = " ";
  23. public bool VerticalHeader { get; set; }
  24. public int Width { get; set; } = 0;
  25. public FrameworkElement? TextToolTip(string? text)
  26. {
  27. if (string.IsNullOrWhiteSpace(text))
  28. return null;
  29. var border = new Border
  30. {
  31. BorderBrush = new SolidColorBrush(Colors.Gray),
  32. BorderThickness = new Thickness(0.75),
  33. CornerRadius = new CornerRadius(5),
  34. Background = new SolidColorBrush(Colors.LightYellow),
  35. Padding = new Thickness(5),
  36. Child = new Label { Content = text }
  37. };
  38. return border;
  39. }
  40. public FrameworkElement? ImageToolTip(BitmapImage? image)
  41. {
  42. if (image == null)
  43. return null;
  44. var result = new Border
  45. {
  46. Background = new SolidColorBrush(Colors.LightYellow),
  47. BorderBrush = new SolidColorBrush(Colors.Gray),
  48. BorderThickness = new Thickness(0.75)
  49. };
  50. result.Child = new Image { Source = image };
  51. return result;
  52. }
  53. public abstract object? Data(CoreRow? row);
  54. }
  55. }