DynamicActionColumn.cs 2.4 KB

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