MobileGridColumn.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Linq.Expressions;
  3. using Syncfusion.SfDataGrid.XForms;
  4. using Xamarin.Forms;
  5. namespace InABox.Mobile
  6. {
  7. public abstract class MobileGridColumn<TEntity, TType> : IMobileGridColumn
  8. {
  9. public MobileGridColumn()
  10. {
  11. Alignment = TextAlignment.Center;
  12. Width = GridLength.Star;
  13. }
  14. public Expression<Func<TEntity,TType>> Column { get; set; }
  15. // This should come from CoreUtils
  16. public String ColumnName => Column?.ToString().Replace(" ","").Replace("x=>x.","") ?? "";
  17. public GridLength Width { get; set; }
  18. public String Caption { get; set; }
  19. public TextAlignment Alignment { get; set; }
  20. public Action<IMobileGridColumn, object> Tapped { get; set; }
  21. public abstract GridColumn CreateColumn();
  22. public TColumn CreateColumn<TColumn>() where TColumn : GridColumn, new()
  23. {
  24. var result = new TColumn();
  25. result.MappingName = ColumnName;
  26. if (Width.IsStar)
  27. result.ColumnSizer = ColumnSizer.Star;
  28. else if (Width.IsAuto)
  29. result.ColumnSizer = ColumnSizer.Auto;
  30. else
  31. {
  32. result.ColumnSizer = ColumnSizer.None;
  33. result.Width = Width.Value;
  34. }
  35. result.TextAlignment = Alignment;
  36. result.HeaderTextAlignment = Alignment;
  37. result.HeaderText = Caption;
  38. return result;
  39. }
  40. }
  41. }