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 Image = System.Windows.Controls.Image;
  8. using Label = System.Windows.Controls.Label;
  9. namespace InABox.DynamicGrid
  10. {
  11. public abstract class DynamicActionColumn : DynamicColumnBase
  12. {
  13. public DynamicActionColumnPosition Position { get; set; } = DynamicActionColumnPosition.End;
  14. public delegate bool ActionDelegate(CoreRow? row);
  15. public delegate FrameworkElement? ActionColumnToolTip(DynamicActionColumn column, CoreRow? row);
  16. public ActionDelegate? Action { get; set; }
  17. public ActionColumnToolTip? ToolTip { get; set; }
  18. public string[]? SelectedFilters { get; set; }
  19. public string[]? Filters { get; set; } = null;
  20. public Func<CoreRow, string[], bool>? FilterRecord { get; set; } = null;
  21. public Func<CoreRow[]?, ContextMenu?>? ContextMenu { get; set; }
  22. public object? Tag { get; set; }
  23. public string HeaderText { get; set; } = " ";
  24. public bool VerticalHeader { get; set; }
  25. public int Width { get; set; } = 0;
  26. public FrameworkElement? TextToolTip(string? text)
  27. {
  28. if (string.IsNullOrWhiteSpace(text))
  29. return null;
  30. var border = new Border
  31. {
  32. BorderBrush = new SolidColorBrush(Colors.Gray),
  33. BorderThickness = new Thickness(0.75),
  34. CornerRadius = new CornerRadius(5),
  35. Background = new SolidColorBrush(Colors.LightYellow),
  36. Padding = new Thickness(5),
  37. Child = new Label { Content = text }
  38. };
  39. return border;
  40. }
  41. public FrameworkElement? ImageToolTip(BitmapImage? image)
  42. {
  43. if (image == null)
  44. return null;
  45. var result = new Border
  46. {
  47. Background = new SolidColorBrush(Colors.LightYellow),
  48. BorderBrush = new SolidColorBrush(Colors.Gray),
  49. BorderThickness = new Thickness(0.75)
  50. };
  51. result.Child = new Image { Source = image };
  52. return result;
  53. }
  54. public abstract object? Data(CoreRow? row);
  55. }
  56. }