DynamicActionColumn.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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<IDynamicGridSummary?>? GetSummary = null;
  20. public Func<IDynamicGridColumnFilter?>? GetFilter = null;
  21. public string[]? ExcludeFilters { get; set; }
  22. public string[]? SelectedFilters { get; set; }
  23. public string[]? Filters { get; set; } = null;
  24. public Func<DynamicActionColumn, string>? GetFilterExpression = null;
  25. public Func<CoreRow, string[], bool>? FilterRecord { get; set; } = null;
  26. public Func<CoreRow[]?, ContextMenu?>? ContextMenu { get; set; }
  27. public string HeaderText { get; set; } = " ";
  28. public bool VerticalHeader { get; set; }
  29. public int Width { get; set; } = 0;
  30. public FrameworkElement? TextToolTip(string? text)
  31. {
  32. if (string.IsNullOrWhiteSpace(text))
  33. return null;
  34. var border = new Border
  35. {
  36. BorderBrush = new SolidColorBrush(Colors.Gray),
  37. BorderThickness = new Thickness(0.75),
  38. CornerRadius = new CornerRadius(5),
  39. Background = new SolidColorBrush(Colors.LightYellow),
  40. Padding = new Thickness(5),
  41. Child = new Label { Content = text }
  42. };
  43. return border;
  44. }
  45. public FrameworkElement? ImageToolTip(BitmapImage? image)
  46. {
  47. if (image == null)
  48. return null;
  49. var result = new Border
  50. {
  51. Background = new SolidColorBrush(Colors.LightYellow),
  52. BorderBrush = new SolidColorBrush(Colors.Gray),
  53. BorderThickness = new Thickness(0.75)
  54. };
  55. result.Child = new Image { Source = image };
  56. return result;
  57. }
  58. public abstract object? Data(CoreRow? row);
  59. public IDynamicGridSummary? Summary() => GetSummary?.Invoke();
  60. }
  61. }