DynamicActionColumn.cs 2.4 KB

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