DFHeaderControl.cs 2.5 KB

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