DynamicTextColumn.cs 789 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using InABox.Core;
  3. namespace InABox.DynamicGrid;
  4. public class DynamicTextColumn : DynamicActionColumn
  5. {
  6. public delegate object GetTextDelegate(CoreRow? row);
  7. public GetTextDelegate Text { get; private set; }
  8. public Alignment Alignment { get; set; }
  9. public string? Format { get; set; }
  10. public DynamicTextColumn(GetTextDelegate text, ActionDelegate? action = null)
  11. {
  12. Alignment = Alignment.MiddleCenter;
  13. Text = text;
  14. Action = action;
  15. VerticalHeader = false;
  16. }
  17. public override object? Data(CoreRow? row)
  18. {
  19. var result = Text?.Invoke(row);
  20. if (!string.IsNullOrWhiteSpace(Format))
  21. return String.Format($"{{0:{Format}}}", result);
  22. return result;
  23. }
  24. }