DynamicImageColumn.cs 862 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Drawing;
  2. using System.Windows.Media.Imaging;
  3. using InABox.Core;
  4. using InABox.WPF;
  5. namespace InABox.DynamicGrid;
  6. public class DynamicImageColumn : DynamicActionColumn
  7. {
  8. private static readonly BitmapImage empty = new Bitmap(32, 32).ToBitmapImage();
  9. public delegate BitmapImage? GetImageDelegate(CoreRow? row);
  10. public DynamicImageColumn(GetImageDelegate image, ActionDelegate? action = null)
  11. {
  12. Image = image;
  13. Action = action;
  14. VerticalHeader = true;
  15. }
  16. public DynamicImageColumn(BitmapImage image, ActionDelegate? action = null)
  17. {
  18. Image = r => image;
  19. Action = action;
  20. }
  21. public GetImageDelegate Image { get; protected set; }
  22. public bool AllowHeaderClick { get; set; } = false;
  23. public override object? Data(CoreRow? row) => Image?.Invoke(row) ?? empty;
  24. }