DynamicCheckColumn.cs 1011 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Linq.Expressions;
  3. using System.Windows.Media.Imaging;
  4. using InABox.Core;
  5. using InABox.DynamicGrid;
  6. using InABox.WPF;
  7. namespace PRSDesktop
  8. {
  9. public class DynamicCheckColumn<T> : DynamicImageColumn
  10. {
  11. private readonly BitmapImage Disabled = Resources.tick.AsGrayScale().AsBitmapImage();
  12. private readonly BitmapImage Enabled = Resources.tick.AsBitmapImage();
  13. private readonly BitmapImage Header;
  14. private readonly Expression<Func<T, bool>> Property;
  15. public DynamicCheckColumn(BitmapImage header, Expression<Func<T, bool>> property) : base(r => null)
  16. {
  17. Header = header;
  18. Property = property;
  19. Image = GetImage;
  20. Action = null;
  21. }
  22. private BitmapImage GetImage(CoreRow? row)
  23. {
  24. if (row == null)
  25. return Header;
  26. var Checked = row.Get(Property).Equals(true);
  27. return Checked ? Enabled : Disabled;
  28. }
  29. }
  30. }