DynamicTickColumn.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Windows.Media.Imaging;
  6. using InABox.Core;
  7. using InABox.WPF;
  8. namespace InABox.DynamicGrid;
  9. public class DynamicTickColumn<T, P> : DynamicImageColumn where T : BaseObject, new() where P : struct
  10. {
  11. private readonly BitmapImage? Data = Wpf.Resources.tick.AsBitmapImage();
  12. private readonly BitmapImage? Header;
  13. private readonly BitmapImage? NoData;
  14. private readonly Expression<Func<T, P>> Property;
  15. public DynamicTickColumn(Expression<Func<T, P>> property, BitmapImage? header, BitmapImage? data, BitmapImage? nodata,
  16. ActionDelegate? action = null) : base(r => null, action)
  17. {
  18. Header = header;
  19. Data = data;
  20. NoData = nodata;
  21. Property = property;
  22. Image = GetImage;
  23. GetFilter = () => new StaticColumnFilter<bool>(HasData, [
  24. new("(Blank)", false),
  25. new("(Not Blank)", true)
  26. ]);
  27. }
  28. private BitmapImage? GetImage(CoreRow? row)
  29. {
  30. if (row == null)
  31. return Header;
  32. return HasData(row) ? Data : NoData;
  33. }
  34. private bool HasData(CoreRow row)
  35. {
  36. var value = row.Get(Property);
  37. return !value.Equals(default(P));
  38. }
  39. }