DFHeaderControl.cs 2.6 KB

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