DFHeaderControl.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using InABox.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Media;
  10. namespace InABox.DynamicGrid
  11. {
  12. public class DFHeaderControl : DynamicFormControl<DFLayoutHeader>
  13. {
  14. public FormHeader Header = null!;
  15. protected override FrameworkElement Create()
  16. {
  17. var style = Control.Style;
  18. Header = new FormHeader
  19. {
  20. Collapsed = Control.Collapsed,
  21. HeaderText = Control.Header,
  22. FontWeight = style.IsBold ? FontWeights.Bold : FontWeights.Normal,
  23. FontStyle = style.IsItalic ? FontStyles.Italic : FontStyles.Normal,
  24. };
  25. Header.CollapsedChanged += (o, c) =>
  26. {
  27. FormDesignGrid.CollapseRows(Header, c);
  28. };
  29. if (FormDesignGrid.IsDesigning)
  30. {
  31. Header.IsEnabled = false;
  32. }
  33. if (style.FontSize > 0)
  34. {
  35. Header.FontSize = style.FontSize;
  36. }
  37. if (style.BackgroundColour != System.Drawing.Color.Empty)
  38. {
  39. Header.Background = new SolidColorBrush(ConvertColour(style.BackgroundColour));
  40. }
  41. if (style.ForegroundColour != System.Drawing.Color.Empty)
  42. {
  43. Header.Foreground = new SolidColorBrush(ConvertColour(style.ForegroundColour));
  44. }
  45. if (style.Underline == UnderlineType.Single)
  46. {
  47. Header.TextDecorations.Add(TextDecorations.Underline);
  48. }
  49. else if (style.Underline == UnderlineType.Double)
  50. {
  51. var underline1 = new TextDecoration
  52. {
  53. Pen = new Pen
  54. {
  55. Brush = Header.Foreground,
  56. }
  57. };
  58. var underline2 = new TextDecoration
  59. {
  60. Pen = new Pen
  61. {
  62. Brush = Header.Foreground,
  63. },
  64. PenOffset = 2
  65. };
  66. Header.TextDecorations.Add(underline1);
  67. Header.TextDecorations.Add(underline2);
  68. }
  69. return Header;
  70. }
  71. private static Color ConvertColour(System.Drawing.Color colour)
  72. {
  73. return new Color { R = colour.R, G = colour.G, B = colour.B, A = colour.A };
  74. }
  75. }
  76. }