DynamicActionColumn.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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)
  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. result.Child = new Image { Source = image };
  51. return result;
  52. }
  53. public abstract object? Data(CoreRow? row);
  54. public IDynamicGridSummary? Summary() => GetSummary?.Invoke();
  55. }
  56. }