DynamicGridColumn.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using InABox.Core;
  5. namespace InABox.DynamicGrid
  6. {
  7. public class ColumnNameGenerator : LookupGenerator<object>
  8. {
  9. public ColumnNameGenerator(object[] items) : base(items)
  10. {
  11. //DynamicGridColumns cols = new DynamicGridColumns();
  12. //cols.ExtractColumns(type, "");
  13. //foreach (DynamicGridColumn col in cols.Where(x => (x.Editor != null) && (x.Editor.Visible != Visible.Disabled)))
  14. // AddValue(col.ColumnName, col.ColumnName);
  15. }
  16. }
  17. public class DynamicGridColumn : DynamicColumnBase
  18. {
  19. public DynamicGridColumn()
  20. {
  21. Editor = new NullEditor();
  22. Lookups = new Dictionary<object, object>();
  23. }
  24. [ComboLookupEditor(typeof(ColumnNameGenerator))]
  25. [EditorSequence(1)]
  26. public string ColumnName { get; set; }
  27. [EditorSequence(2)]
  28. public int Width { get; set; }
  29. [EditorSequence(3)]
  30. public string Format { get; set; }
  31. [EditorSequence(4)]
  32. public string Caption { get; set; }
  33. [EnumLookupEditor(typeof(Alignment))]
  34. [EditorSequence(5)]
  35. public Alignment Alignment { get; set; }
  36. [NullEditor]
  37. public Dictionary<object, object> Lookups { get; set; }
  38. public BaseEditor Editor { get; set; }
  39. public VerticalAlignment VerticalAlignment()
  40. {
  41. if (Alignment.Equals(Alignment.NotSet))
  42. return System.Windows.VerticalAlignment.Center;
  43. if (Alignment.Equals(Alignment.TopLeft) || Alignment.Equals(Alignment.TopCenter) || Alignment.Equals(Alignment.TopRight))
  44. return System.Windows.VerticalAlignment.Top;
  45. if (Alignment.Equals(Alignment.MiddleLeft) || Alignment.Equals(Alignment.MiddleCenter) || Alignment.Equals(Alignment.MiddleRight))
  46. return System.Windows.VerticalAlignment.Center;
  47. return System.Windows.VerticalAlignment.Bottom;
  48. }
  49. public HorizontalAlignment HorizontalAlignment(Type datatype)
  50. {
  51. if (Alignment.Equals(Alignment.NotSet))
  52. return datatype.IsNumeric() ? System.Windows.HorizontalAlignment.Right :
  53. datatype == typeof(bool) ? System.Windows.HorizontalAlignment.Center : System.Windows.HorizontalAlignment.Left;
  54. if (Alignment.Equals(Alignment.TopLeft) || Alignment.Equals(Alignment.MiddleLeft) || Alignment.Equals(Alignment.BottomLeft))
  55. return System.Windows.HorizontalAlignment.Left;
  56. if (Alignment.Equals(Alignment.TopCenter) || Alignment.Equals(Alignment.MiddleCenter) || Alignment.Equals(Alignment.BottomCenter))
  57. return System.Windows.HorizontalAlignment.Center;
  58. return System.Windows.HorizontalAlignment.Right;
  59. }
  60. public override string ToString()
  61. {
  62. return ColumnName;
  63. }
  64. }
  65. }