DynamicActionColumn.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 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, double? maxWidth = null, double? maxHeight = null)
  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. var imageControl = new Image
  51. {
  52. Source = image,
  53. Stretch = Stretch.Uniform
  54. };
  55. if (maxWidth.HasValue)
  56. {
  57. imageControl.MaxWidth = maxWidth.Value;
  58. }
  59. if (maxHeight.HasValue)
  60. {
  61. imageControl.MaxHeight = maxHeight.Value;
  62. }
  63. result.Child = imageControl;
  64. return result;
  65. }
  66. public abstract object? Data(CoreRow? row);
  67. public IDynamicGridSummary? Summary() => GetSummary?.Invoke();
  68. }
  69. }