DynamicActionColumn.cs 2.5 KB

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