DynamicImageColumn.cs 910 B

12345678910111213141516171819202122232425262728293031323334353637
  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. protected DynamicImageColumn()
  11. {
  12. }
  13. public DynamicImageColumn(GetImageDelegate image, ActionDelegate? action = null)
  14. {
  15. Image = image;
  16. Action = action;
  17. VerticalHeader = true;
  18. }
  19. public DynamicImageColumn(BitmapImage image, ActionDelegate? action = null)
  20. {
  21. Image = r => image;
  22. Action = action;
  23. }
  24. public GetImageDelegate Image { get; protected set; }
  25. public bool AllowHeaderClick { get; set; } = false;
  26. public override object? Data(CoreRow? row) => Image?.Invoke(row) ?? empty;
  27. }